Commit 06bf009d
06bf009dd646Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
codegen: uninitialised constant read raises NameError
ConstantReadNode for an unknown name used to emit a stderr warning and return 0, which let `X = X + 1` quietly produce 1 and `puts NONEXISTENT` print 0 instead of failing. Emit a stmt-expression raising NameError so a rescue can catch it and unrescued runs surface the bug.
Fixes #837 Fixes #838
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 06bf009dd646
- Parent
- ff20bd874b7f
spinel_codegen.rbmodifiedView file
@@ -13492,8 +13492,14 @@
1349213492
return "sp_ruby_platform_str()"1349313493
end1349413494
if is_known_constant_name(rname) == 013495-
warn_unresolved_const(rname)13496-
return "0"13495+
# Uninitialised constant — raise NameError at runtime (CRuby13496+
# behaviour). Stmt-expression so the call site still gets an13497+
# expression value of the inferred type (the cast is reached13498+
# only after sp_raise_cls's longjmp, so it's dead code that13499+
# has to type-check).13500+
@needs_setjmp = 113501+
rt_uc = infer_type(nid)13502+
return "({ sp_raise_cls(\"NameError\", \"uninitialized constant " + rname + "\"); " + c_default_val(rt_uc) + "; })"1349713503
end1349813504
return rname1349913505
endtest/uninit_const_raises_nameerror.rbaddedView file
Loading diff…