Commit e8db1839

e8db1839a6ffMerged

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

Description

fix(analyze): nil→nullable assignment doesn't double the ? (#804)

When an ivar started as nil ('nil' type) and was later assigned from an already-nullable source (e.g. 'string?'), the slot was widened to '<new_type>?' unconditionally -- producing 'string??'. Codegen doesn't recognise the double-? form, so writes silently got the wrong c_type lookup downstream.

Fix: when new_type is already nullable, keep it as-is instead of suffixing another '?'.

Closes #804

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

Details

Commit
e8db1839a6ff
Parent
add5a8e965be

spinel_analyze.rbmodifiedView file

@@ -9291,7 +9291,14 @@
92919291 @cls_ivar_types_version = @cls_ivar_types_version + 1
92929292 end
92939293 elsif old == "nil" && is_nullable_pointer_type(new_type) == 1
9294- types[k] = new_type + "?"
9294+ # Issue #804: if new_type already ends in '?', don't append a
9295+ # second one. e.g. `@x = nil` then `@x = val` where val is
9296+ # already nullable -> stay as "string?", not "string??".
9297+ if is_nullable_type(new_type) == 1
9298+ types[k] = new_type
9299+ else
9300+ types[k] = new_type + "?"
9301+ end
92959302 @cls_ivar_types[ci] = types.join(";")
92969303 @cls_ivar_types_version = @cls_ivar_types_version + 1
92979304 # Same base, one nullable: keep / adopt the nullable form