Commit e9b94657

e9b946576a44Merged

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

Description

Unbox poly setter value into narrow attr_accessor field

When an inherited factory (def self.create; new(attrs); end) forwards an incompatible argument type to a subclass constructor, the ctor parameter unifies to poly (sp_RbVal) across its call sites. If the inherited attr_accessor field it is assigned to stays narrow (mrb_int, pinned elsewhere by @id = 0), the inlined self.attr = val setter wrote the poly value directly into the narrow field, emitting mrb_int = sp_RbVal which fails C compilation.

Add the missing slot-concrete / arg-poly case to the setter's coercion ladder: unbox the poly value to the field's concrete C type. This mirrors the existing poly-receiver dispatch arm. Any program that previously compiled could not have reached this case (it was an ill-typed assignment), so the change is additive.

Fixes #1275

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

Details

Commit
e9b946576a44
Parent
c688e6c3270a

spinel_codegen.rbmodifiedView file

@@ -39903,6 +39903,14 @@
3990339903 end
3990439904 if slot_t == "poly"
3990539905 arg0_w = box_value_to_poly(arg_t_aw, arg0_w)
39906+ elsif arg_t_aw == "poly" && slot_t != "" && slot_t != "poly"
39907+ # An inherited factory widened the subclass ctor param to poly
39908+ # (e.g. `self.create` forwarding `new(attrs)` with a Hash) while
39909+ # this attr_accessor field stayed narrow. Unbox to the field's
39910+ # concrete C type so the direct write type-checks instead of
39911+ # emitting `mrb_int = sp_RbVal`. Mirrors the poly-receiver
39912+ # dispatch arm's slot-concrete / arg-poly case.
39913+ arg0_w = unbox_poly_to(slot_t, arg0_w)
3990639914 elsif slot_t == "bigint" && arg_t_aw == "int"
3990739915 # promote-mode-widened ivar: wrap an int rhs.
3990839916 @needs_bigint = 1