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
end end if cpname != "" return cpname if is_known_constant_name(cpname) == 1 return cpname end # Unresolved qualified constant (e.g. a const supplied by an # ignored require). The flat fall-through used to emit the bare # `Mylib_VERSION` identifier, which is undeclared C and fails to # compile. Degrade to a runtime NameError carrying the inferred # type, mirroring the ConstantReadNode arm above. @needs_setjmp = 1 rt_cpn = infer_type(nid) return "({ sp_raise_cls(\"NameError\", \"uninitialized constant " + rname + "::" + nname + "\"); " + c_default_val(rt_cpn) + "; })" end end return @nd_name[nid] if is_known_constant_name(@nd_name[nid]) == 1 return @nd_name[nid] end @needs_setjmp = 1 rt_cpn2 = infer_type(nid) return "({ sp_raise_cls(\"NameError\", \"uninitialized constant " + @nd_name[nid] + "\"); " + c_default_val(rt_cpn2) + "; })" end if t == "LambdaNode" return compile_lambda_expr(nid)test/const_path_unresolved_require.rbaddedView file
Loading diff…
test/const_path_unresolved_require.rb.expectedaddedView file
Loading diff…