Commit ad486706
ad486706fe5fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Type module/class-body constant refs under their lexical scope
Interpolating a String constant defined in the same module/class body emitted the constant's raw pointer instead of its value (v#{A} -> a number). The constant-initializer-RHS annotation pass cached the inner constant reference's type without setting the lexical scope, so a bare A inside module M resolved to no constant and fell through to the int default; codegen then read the stale cache and interpolated A as %lld.
Set @current_lexical_scope to the constant's defining namespace before walking each init RHS, mirroring the @multi_const_inits loop directly below. Now A resolves to M_A (String) and interpolates correctly.
This is part A of the report; the definition-time body side-effect gap (part B) is separate.
Refs #1256
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- ad486706fe5f
- Parent
- d3c0a37fa320
spinel_analyze.rbmodifiedView file
while cei < @const_expr_ids.length ceid = @const_expr_ids[cei] if ceid >= 0 # Set the lexical scope to the const's defining namespace so a bare # constant reference inside the RHS (`V = "v#{A}"` where both live # in `module M`) resolves to `M_A` rather than falling through to # the int default. Without this the cached type for the inner ref # was "int" and interpolation/codegen treated the String constant # as a raw pointer. Mirrors the @multi_const_inits loop below. saved_lex_c = @current_lexical_scope if cei < @const_scope_names.length @current_lexical_scope = @const_scope_names[cei] else @current_lexical_scope = "" end walk_and_cache(ceid) @current_lexical_scope = saved_lex_c end cei = cei + 1 endtest/module_body_string_const_interp.rbaddedView file
Loading diff…
test/module_body_string_const_interp.rb.expectedaddedView file
Loading diff…