Commit be4469ee
be4469eeb0b3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Widen a nil-assigned local to poly (nullable)
A local that takes a nil assignment is now poly rather than ignoring the nil, so genuinely-nullable variables (y = found; y = nil; y.nil?) and nil/value mixes work. With the poly value system in place this no longer regresses deferred-init code -- the typed-context cascade the comment warned about is covered by poly arithmetic/dispatch/print.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- be4469eeb0b3
- Parent
- 69492116bfa0
src/analyze.cmodifiedView file
@@ -838,7 +838,7 @@
838838
newt = infer_type(c, nt_ref(nt, id, "value"));839839
/* a `x = nil` write doesn't pin the type: nil is the absent/default840840
value, so the variable takes its non-nil assignments' type */841-
if (newt == TY_NIL) newt = TY_UNKNOWN;841+
if (newt == TY_NIL) newt = TY_POLY;842842
}843843
else if (!strcmp(ty, "LocalVariableOperatorWriteNode")) {844844
nm = nt_str(nt, id, "name");