Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0fd7a5f

Browse files
committed
Ensure lambda block-local variables are handled properly
1 parent 0c5728f commit 0fd7a5f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/syntax_tree/parser.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,11 +2054,10 @@ def lambda_locals(source)
20542054
tokens[(index + 1)..].each_with_object([]) do |token, locals|
20552055
(lineno, column), type, value, = token
20562056

2057-
# Make the state transition for the parser. This is going to raise a
2058-
# KeyError if we don't have a transition for the current state and type.
2059-
# But that shouldn't actually be possible because ripper would have
2060-
# found a syntax error by then.
2061-
state = transitions[state].fetch(type)
2057+
# Make the state transition for the parser. If there isn't a transition
2058+
# from the current state to a new state for this type, then we're in a
2059+
# pattern that isn't actually locals. In that case we can return [].
2060+
state = transitions[state].fetch(type) { return [] }
20622061

20632062
# If we hit an identifier, then add it to our list.
20642063
next if type != :on_ident

test/fixtures/lambda.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@
6666
) {}
6767
-
6868
->(; a, b) {}
69+
%
70+
->(a = (b; c)) {}
71+
-
72+
->(
73+
a = (
74+
b
75+
c
76+
)
77+
) do
78+
end

0 commit comments

Comments
 (0)