Commit c688e6c3

c688e6c3270aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified

Description

Degrade unresolved qualified constants to a runtime NameError

A qualified constant (Foo::Bar) resolving to no registered constant, class, module, or builtin used to fall through to a bare Foo_Bar C identifier, which is undeclared and fails C compilation. This commonly surfaces when the constant is supplied by a require Spinel cannot honor (require "mylib/version"; Mylib::VERSION).

Mirror the ConstantReadNode arm: when the flattened path name matches no known constant, emit a runtime NameError carrying the inferred type instead of the bare identifier. Programs now compile and raise uninitialized constant Foo::Bar, matching the unqualified-constant path. Any program that previously compiled could not have reached this fall-through (it was undeclared C), so the change is additive.

Fixes #1273

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

Details

Commit
c688e6c3270a
Parent
ef203c2b5883

spinel_codegen.rbmodifiedView file

@@ -15052,10 +15052,25 @@
1505215052 end
1505315053 end
1505415054 if cpname != ""
15055- return cpname
15055+ if is_known_constant_name(cpname) == 1
15056+ return cpname
15057+ end
15058+ # Unresolved qualified constant (e.g. a const supplied by an
15059+ # ignored require). The flat fall-through used to emit the bare
15060+ # `Mylib_VERSION` identifier, which is undeclared C and fails to
15061+ # compile. Degrade to a runtime NameError carrying the inferred
15062+ # type, mirroring the ConstantReadNode arm above.
15063+ @needs_setjmp = 1
15064+ rt_cpn = infer_type(nid)
15065+ return "({ sp_raise_cls(\"NameError\", \"uninitialized constant " + rname + "::" + nname + "\"); " + c_default_val(rt_cpn) + "; })"
1505615066 end
1505715067 end
15058- return @nd_name[nid]
15068+ if is_known_constant_name(@nd_name[nid]) == 1
15069+ return @nd_name[nid]
15070+ end
15071+ @needs_setjmp = 1
15072+ rt_cpn2 = infer_type(nid)
15073+ return "({ sp_raise_cls(\"NameError\", \"uninitialized constant " + @nd_name[nid] + "\"); " + c_default_val(rt_cpn2) + "; })"
1505915074 end
1506015075 if t == "LambdaNode"
1506115076 return compile_lambda_expr(nid)