Commit 385a3aa6
385a3aa68af6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #96 from mame/fix/initialize-param-type-clobber
fix(codegen): merge initialize param types from call sites and body
Details
- Commit
- 385a3aa68af6
- Parent
- 45ac5ee6dce8
- Merge parent
- 2bc0d7b2399b
spinel_codegen.rbmodifiedView file
@@ -6456,7 +6456,32 @@
64566456
if mnames[j] == "initialize"64576457
k = 064586458
while k < pnames.length6459-
pt = infer_init_param_type(i, pnames[k])6459+
# Two sources of param types feed this slot:6460+
# existing_pt: from infer_constructor_types scanning Foo.new(...)6461+
# call sites (already widened to "poly" via unify_call_types6462+
# when call sites disagree).6463+
# body_pt: from scanning the initialize body for `@x = param`6464+
# ivar writes; "int" means "no info" (the fallback).6465+
# Body inference must not silently clobber call-site evidence.6466+
existing_pt = "int"6467+
if k < ptypes.length6468+
existing_pt = ptypes[k]6469+
end6470+
body_pt = infer_init_param_type(i, pnames[k])6471+
pt = body_pt6472+
if existing_pt != "int" && existing_pt != "nil"6473+
if body_pt == "int" || body_pt == "nil"6474+
# Body has no info; keep call-site type.6475+
pt = existing_pt6476+
elsif existing_pt == "poly"6477+
# Call sites already widened to poly; do not narrow.6478+
pt = "poly"6479+
elsif body_pt != existing_pt && body_pt != "poly"6480+
# Two concrete types disagree; demote to poly.6481+
@needs_rb_value = 16482+
pt = "poly"6483+
end6484+
end64606485
if k < ptypes.length64616486
ptypes[k] = pt64626487
endtest/initialize_param_poly_call_sites.rbaddedView file
Loading diff…
test/initialize_param_through_call.rbaddedView file
Loading diff…