Skip to content

Commit bdd0580

Browse files
fix wrong context
1 parent 9fd2372 commit bdd0580

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/code/object/identifier_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def call(**args)
2020
context: context,
2121
assignment_operator: assignment_operator,
2222
code_value: code_value,
23-
**args
23+
**args.except(:context)
2424
)
2525
else
2626
assign_with_setter(

spec/code/object/identifier_list_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@
33
require "spec_helper"
44

55
RSpec.describe Code::Object::IdentifierList do
6+
it "assigns square bracket keys in parent context from nested scopes" do
7+
parent_context = Code::Object::Context.new
8+
child_context = Code::Object::Context.new({}, parent_context)
9+
code_identifier = Code::Object::String.new("github")
10+
code_index = Code::Object::Integer.new(1)
11+
12+
parent_context.code_set(code_identifier, Code::Object::Dictionary.new(a: 1))
13+
14+
identifier_list = described_class.new([code_identifier, code_index])
15+
16+
identifier_list.call(
17+
operator: "=",
18+
arguments: Code::Object::List.new([Code::Object::Integer.new(2)]),
19+
context: child_context,
20+
error: StringIO.new,
21+
input: StringIO.new,
22+
object: Code::Object::Global.new,
23+
output: StringIO.new,
24+
source: ""
25+
)
26+
27+
expect(parent_context.code_fetch(code_identifier).code_fetch(code_index)).to eq(
28+
Code::Object::Integer.new(2)
29+
)
30+
end
31+
632
it "keeps context for ||= assignments in nested context receivers" do
733
code_context = Code::Object::Context.new
834
code_identifier = Code::Object::String.new("value")

0 commit comments

Comments
 (0)