Commit cc56bd44

cc56bd446ad2Merged

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

Description

Merge pull request #164 from mame/pr/const-init-block-param-scan

fix(codegen): scan const-init expressions for block-param locals

Details

Commit
cc56bd446ad2
Parent
8ec719212393
Merge parent
991d5fe0dc3e

spinel_codegen.rbmodifiedView file

@@ -13557,6 +13557,18 @@
1355713557 end
1355813558 end
1355913559 }
13560+ # Constant initializer expressions get compiled into main() right
13561+ # before the user statements run, but the block params they
13562+ # introduce (e.g. \`FRAME = [...].map { |n| ... }\`) need
13563+ # declarations in the same scope. Scan each const's RHS so the
13564+ # block param names land in lnames alongside the user-stmt locals.
13565+ ci_lc = 0
13566+ while ci_lc < @const_expr_ids.length
13567+ if @const_expr_ids[ci_lc] >= 0
13568+ scan_locals(@const_expr_ids[ci_lc], lnames, ltypes, empty_params)
13569+ end
13570+ ci_lc = ci_lc + 1
13571+ end
1356013572
1356113573 # Declare vars for second pass to resolve dependent types
1356213574 j = 0