From 7db4ce13ed051bc422c5db594bb41edbaeb1ae35 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Thu, 5 Oct 2023 20:41:41 +0100 Subject: [ruby/prism] Introduce transparent scopes. A transparent scope is a scope that cannot have local variables added to it's local table. When a local is added to it's table, it instead gets added to the first non-transparent parent scope. This is used in for loops to ensure the correct depth for local variables inside the body https://github.com/ruby/prism/commit/ddb8e82253 Co-Authored-By: Kevin Newton --- test/prism/snapshots/for.txt | 12 ++++++------ test/prism/snapshots/whitequark/for.txt | 4 ++-- test/prism/snapshots/whitequark/for_mlhs.txt | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/prism/snapshots/for.txt b/test/prism/snapshots/for.txt index a0485a57ff..cfcf3e4d36 100644 --- a/test/prism/snapshots/for.txt +++ b/test/prism/snapshots/for.txt @@ -23,7 +23,7 @@ │ │ └── body: (length: 1) │ │ └── @ LocalVariableReadNode (location: (2,0)-(2,1)) │ │ ├── name: :i - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── for_keyword_loc: (1,0)-(1,3) = "for" │ ├── in_keyword_loc: (1,6)-(1,8) = "in" │ ├── do_keyword_loc: ∅ @@ -48,7 +48,7 @@ │ │ └── body: (length: 1) │ │ └── @ LocalVariableReadNode (location: (5,16)-(5,17)) │ │ ├── name: :i - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── for_keyword_loc: (5,0)-(5,3) = "for" │ ├── in_keyword_loc: (5,6)-(5,8) = "in" │ ├── do_keyword_loc: ∅ @@ -80,7 +80,7 @@ │ │ └── body: (length: 1) │ │ └── @ LocalVariableReadNode (location: (8,0)-(8,1)) │ │ ├── name: :i - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── for_keyword_loc: (7,0)-(7,3) = "for" │ ├── in_keyword_loc: (7,8)-(7,10) = "in" │ ├── do_keyword_loc: ∅ @@ -115,7 +115,7 @@ │ │ └── body: (length: 1) │ │ └── @ LocalVariableReadNode (location: (12,0)-(12,1)) │ │ ├── name: :i - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── for_keyword_loc: (11,0)-(11,3) = "for" │ ├── in_keyword_loc: (11,10)-(11,12) = "in" │ ├── do_keyword_loc: ∅ @@ -140,7 +140,7 @@ │ │ └── body: (length: 1) │ │ └── @ LocalVariableReadNode (location: (16,0)-(16,1)) │ │ ├── name: :i - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── for_keyword_loc: (15,0)-(15,3) = "for" │ ├── in_keyword_loc: (15,6)-(15,8) = "in" │ ├── do_keyword_loc: (15,15)-(15,17) = "do" @@ -165,7 +165,7 @@ │ └── body: (length: 1) │ └── @ LocalVariableReadNode (location: (19,16)-(19,17)) │ ├── name: :i - │ └── depth: 0 + │ └── depth: 1 ├── for_keyword_loc: (19,0)-(19,3) = "for" ├── in_keyword_loc: (19,6)-(19,8) = "in" ├── do_keyword_loc: ∅ diff --git a/test/prism/snapshots/whitequark/for.txt b/test/prism/snapshots/whitequark/for.txt index d4d4dc1602..1006da9272 100644 --- a/test/prism/snapshots/whitequark/for.txt +++ b/test/prism/snapshots/whitequark/for.txt @@ -32,7 +32,7 @@ │ │ │ └── arguments: (length: 1) │ │ │ └── @ LocalVariableReadNode (location: (1,18)-(1,19)) │ │ │ ├── name: :a - │ │ │ └── depth: 0 + │ │ │ └── depth: 1 │ │ ├── closing_loc: ∅ │ │ ├── block: ∅ │ │ ├── flags: ∅ @@ -70,7 +70,7 @@ │ │ └── arguments: (length: 1) │ │ └── @ LocalVariableReadNode (location: (3,16)-(3,17)) │ │ ├── name: :a - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── closing_loc: ∅ │ ├── block: ∅ │ ├── flags: ∅ diff --git a/test/prism/snapshots/whitequark/for_mlhs.txt b/test/prism/snapshots/whitequark/for_mlhs.txt index ef15199a80..93b0eb3297 100644 --- a/test/prism/snapshots/whitequark/for_mlhs.txt +++ b/test/prism/snapshots/whitequark/for_mlhs.txt @@ -39,10 +39,10 @@ │ │ └── arguments: (length: 2) │ │ ├── @ LocalVariableReadNode (location: (1,19)-(1,20)) │ │ │ ├── name: :a - │ │ │ └── depth: 0 + │ │ │ └── depth: 1 │ │ └── @ LocalVariableReadNode (location: (1,22)-(1,23)) │ │ ├── name: :b - │ │ └── depth: 0 + │ │ └── depth: 1 │ ├── closing_loc: ∅ │ ├── block: ∅ │ ├── flags: ∅ -- cgit v1.2.3