Commit cecd16e7
cecd16e7960aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #253 from mame/pr/attr-writer-box-poly
fix(codegen): attr-writer boxes rhs when slot is poly
Details
- Commit
- cecd16e7960a
- Parent
- 9f6587ba9e30
- Merge parent
- 83f9bd866c8e
spinel_codegen.rbmodifiedView file
@@ -22298,7 +22298,31 @@
2229822298
j = 02229922299
while j < writers.length2230022300
if writers[j] == bname22301-
return "(" + rc + arrow + sanitize_ivar(bname) + " = " + compile_arg0(nid) + ")"22301+
# Box the rhs when the slot is poly so the assignment22302+
# type-matches at C level. Without this, an obj-typed22303+
# rhs flowing into a poly slot emits22304+
# `slot = ptr_value` with a struct LHS — rejected by22305+
# C compile. Use a comma expression so the value of22306+
# the chain is the *original* rhs (typed), preserving22307+
# Ruby's `obj.attr = v` semantics for downstream22308+
# consumers like `local = obj.attr = v` or22309+
# `puts(obj.attr = v)` where `v`'s static type drives22310+
# the formatter / cast.22311+
slot_t = cls_ivar_type(ci, "@" + bname)22312+
args_id_w = @nd_arguments[nid]22313+
arg0_w = compile_arg0(nid)22314+
if slot_t == "poly"22315+
arg_t = "int"22316+
if args_id_w >= 022317+
arg_ids_w = get_args(args_id_w)22318+
if arg_ids_w.length > 022319+
arg_t = infer_type(arg_ids_w[0])22320+
end22321+
end22322+
boxed = box_value_to_poly(arg_t, arg0_w)22323+
return "(" + rc + arrow + sanitize_ivar(bname) + " = " + boxed + ", " + arg0_w + ")"22324+
end22325+
return "(" + rc + arrow + sanitize_ivar(bname) + " = " + arg0_w + ")"2230222326
end2230322327
j = j + 12230422328
end@@ -26804,7 +26828,22 @@
2680426828
if is_value_type_obj(rt) == 12680526829
arrow2 = "."2680626830
end26807-
emit(" " + rc + arrow2 + sanitize_ivar(bname) + " = " + compile_arg0(nid) + ";")26831+
# Box rhs when the slot is poly, same as the26832+
# expression-form attr_writer above.26833+
slot_t = cls_ivar_type(r_ci, "@" + bname)26834+
arg0_w = compile_arg0(nid)26835+
if slot_t == "poly"26836+
args_id_w = @nd_arguments[nid]26837+
arg_t = "int"26838+
if args_id_w >= 026839+
arg_ids_w = get_args(args_id_w)26840+
if arg_ids_w.length > 026841+
arg_t = infer_type(arg_ids_w[0])26842+
end26843+
end26844+
arg0_w = box_value_to_poly(arg_t, arg0_w)26845+
end26846+
emit(" " + rc + arrow2 + sanitize_ivar(bname) + " = " + arg0_w + ";")2680826847
return 12680926848
end2681026849
endtest/attr_writer_poly_box.rbaddedView file
Loading diff…