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
ltypes[k] = ltypes2[j] set_var_type(lnames[k], ltypes2[j]) end elsif ltypes[k] == "nil" && is_nullable_pointer_type(ltypes2[j]) == 1 # `prev = nil` then `prev = obj` — upgrade to obj? if is_nullable_type(ltypes2[j]) == 1 ltypes[k] = ltypes2[j] else ltypes[k] = ltypes2[j] + "?" end set_var_type(lnames[k], ltypes[k]) end end k = k + 1