Commit 48c7ca50

48c7ca50ab91Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

codegen,analyze: resolve an instance_eval ivar write against the rebound class

Inside an instance_eval/exec splice the block scope has no class_id, so an @v = 42 write looked up the ivar type as UNKNOWN: codegen skipped boxing a scalar rhs into the poly ivar slot, and infer reported the rhs (int) type rather than the ivar slot, so a splice ending in such a write sized its result temp to mrb_int. Resolve the ivar's class via g_ie_class_id (codegen) and an_ie_class_id (analyze). Fixes instance_eval_block_params.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
48c7ca50ab91
Parent
9c34936257f7

src/analyze_infer.cmodifiedView file

@@ -2565,8 +2565,11 @@
25652565 slot, and inference must match to keep `@x = @a = expr` boxing consistent. */
25662566 const char *nm = nt_str(nt, id, "name");
25672567 Scope *s = comp_scope_of(c, id);
2568- if (s->class_id < 0) return infer_type(c, nt_ref(nt, id, "value"));
2569- ClassInfo *ci = &c->classes[s->class_id];
2568+ /* inside an instance_eval/exec splice the block scope has no class_id; the
2569+ ivar belongs to the rebound receiver class (an_ie_class_id). */
2570+ int wcls = s->class_id >= 0 ? s->class_id : an_ie_class_id;
2571+ if (wcls < 0) return infer_type(c, nt_ref(nt, id, "value"));
2572+ ClassInfo *ci = &c->classes[wcls];
25702573 int iv = nm ? comp_ivar_index(ci, nm) : -1;
25712574 return iv >= 0 ? ci->ivar_types[iv] : TY_UNKNOWN;
25722575 }