Skip to content

Commit f5c6f6c

Browse files
Dale-Blackclaude
andcommitted
Fix captured_vars lookup for SlotNumber(1) in optimize=false IR
Closure field access getfield(#self#, :name) uses Core.Argument(1) in optimized IR but Core.SlotNumber(1) in unoptimized IR. Handle both. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0550555 commit f5c6f6c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/compiler/codegen.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,9 @@ function compile_call(ctx::JSCompilationContext, expr::Expr)
827827
obj = args[2]
828828
field_arg = args[3]
829829
# Closure captured variable: getfield(self, :name)
830-
if obj isa Core.Argument && obj.n == 1 && field_arg isa QuoteNode && field_arg.value isa Symbol
830+
# In optimized IR: Core.Argument(1), in unoptimized IR: Core.SlotNumber(1)
831+
is_self = (obj isa Core.Argument && obj.n == 1) || (obj isa Core.SlotNumber && obj.id == 1)
832+
if is_self && field_arg isa QuoteNode && field_arg.value isa Symbol
831833
fname = field_arg.value
832834
if haskey(ctx.captured_vars, fname)
833835
return ctx.captured_vars[fname]

0 commit comments

Comments
 (0)