Commit 7416ab24
7416ab243e35Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Coerce poly RHS in float op-assign and unknown-left || to scalar
- where level1 widened to poly: sp_poly_mul yields a boxed value but y is mrb_float; coerce a poly RHS via sp_poly_to_f in the float op-assign path.
- chained over poly locals: a LocalVariableWriteNode now reports its slot type (matching codegen's slot-chaining lowering) instead of the assigned value type, so the outer assign no longer double-boxes.
- in dead code: an unresolved (UNKNOWN) || left emits a poly fallback; coerce it to the unified int/float result.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 7416ab243e35
- Parent
- da8ab9bb3036
src/analyze_infer.cmodifiedView file
@@ -1944,8 +1944,17 @@
19441944
return TY_RANGE;19451945
}19461946
if (!strcmp(ty, "LambdaNode")) return TY_PROC;1947-
/* an assignment expression evaluates to the assigned value */1948-
if (!strcmp(ty, "LocalVariableWriteNode")) return infer_type(c, nt_ref(nt, id, "value"));1947+
/* an assignment expression evaluates to the assigned value -- but codegen1948+
lowers `x = expr` to `({ lv_x = ...; lv_x; })`, so the chain value IS the1949+
slot. Return the local's slot type (when known) so a chained `a = b = expr`1950+
boxes consistently with the slot, mirroring the ivar-write rule below. */1951+
if (!strcmp(ty, "LocalVariableWriteNode")) {1952+
const char *lwn = nt_str(nt, id, "name");1953+
Scope *lws = comp_scope_of(c, id);1954+
LocalVar *lwv = lwn ? scope_local(lws, lwn) : NULL;1955+
if (lwv && lwv->type != TY_UNKNOWN) return lwv->type;1956+
return infer_type(c, nt_ref(nt, id, "value"));1957+
}19491958
if (!strcmp(ty, "InstanceVariableWriteNode") ||19501959
!strcmp(ty, "InstanceVariableOrWriteNode") ||19511960
!strcmp(ty, "InstanceVariableAndWriteNode") ||src/codegen_expr.cmodifiedView file
Loading diff…
src/codegen_stmt.cmodifiedView file
Loading diff…