Commit 8ddbbcf9
8ddbbcf97492Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add begin/rescue as a value (and method-level rescue value)
A begin/rescue in tail position (or a method whose body is begin/rescue)
yields a value: a result temp is assigned in both the success and
handler branches (via the tail logic, redirected from return to
<temp> = through g_result_var), then returned. analyze infers the
BeginNode value as the body value unified with each handler's value.
risky-style methods (compute or rescue to a fallback) and method-level
rescue match CRuby. make test: 47.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 8ddbbcf97492
- Parent
- 7220b833a15c
src/analyze.cmodifiedView file
@@ -397,6 +397,16 @@
397397
if (lt == TY_BOOL && rt == TY_BOOL) return TY_BOOL;398398
return ty_unify(lt, rt); /* value form: a || b -> common type */399399
}400+
if (!strcmp(ty, "BeginNode")) {401+
/* value = body value unified with each rescue handler's value */402+
int body = nt_ref(nt, id, "statements");403+
TyKind r = body >= 0 ? infer_type(c, body) : TY_NIL;404+
for (int rs = nt_ref(nt, id, "rescue_clause"); rs >= 0; rs = nt_ref(nt, rs, "subsequent")) {405+
int st = nt_ref(nt, rs, "statements");406+
r = ty_unify(r, st >= 0 ? infer_type(c, st) : TY_NIL);407+
}408+
return r;409+
}400410
if (!strcmp(ty, "CallNode")) return infer_call(c, id);401411
402412
return TY_UNKNOWN;src/codegen.cmodifiedView file
Loading diff…