Commit a0a28090

a0a28090b95cMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

fix: upgrade 'nil' local-var type to T? when later assigned a T

prev = nil; ...; prev = obj_N should leave prev typed as obj_N?. scan_locals' in-pass upgrade path only fires when both sides' types are known to it at the moment of the write, but the first pass sees the RHS of a later read-var assignment as plain 'int' (since the var isn't in scope yet). declare_method_locals re-runs scan_locals a second time with types in scope, then copies the improved type back — but that copy only handled the 'int → richer' case, not 'nil → richer'. Extend it to handle nil → nullable-pointer upgrades too.

Fixes the type-confusion warnings in linked_list.rb's list_reverse (lv_prev was declared mrb_int and then assigned sp_LNode *).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
a0a28090b95c
Parent
03a811a21209

spinel_codegen.rbmodifiedView file

@@ -9888,6 +9888,14 @@
98889888 ltypes[k] = ltypes2[j]
98899889 set_var_type(lnames[k], ltypes2[j])
98909890 end
9891+ elsif ltypes[k] == "nil" && is_nullable_pointer_type(ltypes2[j]) == 1
9892+ # `prev = nil` then `prev = obj` — upgrade to obj?
9893+ if is_nullable_type(ltypes2[j]) == 1
9894+ ltypes[k] = ltypes2[j]
9895+ else
9896+ ltypes[k] = ltypes2[j] + "?"
9897+ end
9898+ set_var_type(lnames[k], ltypes[k])
98919899 end
98929900 end
98939901 k = k + 1