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

@@ -33320,7 +33320,20 @@
3332033320 while cei < @const_expr_ids.length
3332133321 ceid = @const_expr_ids[cei]
3332233322 if ceid >= 0
33323+ # Set the lexical scope to the const's defining namespace so a bare
33324+ # constant reference inside the RHS (`V = "v#{A}"` where both live
33325+ # in `module M`) resolves to `M_A` rather than falling through to
33326+ # the int default. Without this the cached type for the inner ref
33327+ # was "int" and interpolation/codegen treated the String constant
33328+ # as a raw pointer. Mirrors the @multi_const_inits loop below.
33329+ saved_lex_c = @current_lexical_scope
33330+ if cei < @const_scope_names.length
33331+ @current_lexical_scope = @const_scope_names[cei]
33332+ else
33333+ @current_lexical_scope = ""
33334+ end
3332333335 walk_and_cache(ceid)
33336+ @current_lexical_scope = saved_lex_c
3332433337 end
3332533338 cei = cei + 1
3332633339 end