Commit c360ff73
c360ff731f28Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +2 added
Description
test: regression for #647 deferred const init
Pin the repro from PR #648 (merged in 874ef05) — top-level
CFG_VOCAB = cfg.nested.v where cfg is a main local. Before
the fix this printed 0 because the const-init pre-loop fired
before cfg = Cfg.new(inner); after the fix the body-loop's
deferred emit lands at source order and prints 42.
Refs #647, #648.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- c360ff731f28
- Parent
- b801924b7c1d
test/const_init_defers_for_main_local.rbaddedView file
1+
# Issue #647: a top-level `CONST = recv.method` initializer whose2+
# RHS reads a main-scope local used to emit BEFORE the body3+
# statements ran. Codegen's const-init pre-loop planted4+
# `cst_X = lv_y.iv_z;` at the top of `main`, before `lv_y =5+
# sp_Y_new()` ever ran, so the chain read from a zero-initialized6+
# struct and the const ended up as 0 (or SIGSEGV when the call7+
# reached FFI). Reporter hit the FFI crash variant in tinynn8+
# config loading.9+
#10+
# Fix (PR #648): expr_reads_main_local detects the dependency,11+
# the pre-loop skips flagged consts, and the body-statement loop12+
# emits them in source order — by then the local has been13+
# assigned.14+
15+
class Cfg16+
attr_reader :nested17+
def initialize(n); @nested = n; end18+
end19+
20+
class Inner21+
attr_reader :v22+
def initialize; @v = 42; end23+
end24+
25+
inner = Inner.new26+
cfg = Cfg.new(inner)27+
CFG_VOCAB = cfg.nested.v # ← used to read zero-init lv_cfg, returns 028+
puts CFG_VOCAB.to_stest/const_init_defers_for_main_local.rb.expectedaddedView file
Loading diff…