Skip to content

Commit

Permalink
Add end location to Select
Browse files Browse the repository at this point in the history
  • Loading branch information
FnControlOption committed Feb 11, 2025
1 parent 35fc6d6 commit 673353c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,7 @@ module Crystal
assert_end_location "foo.bar= *baz"
assert_end_location "case :foo; when :bar; 2; end"
assert_end_location %(asm("nop" ::))
assert_end_location "select; when foo; 2; end"

assert_syntax_error %({"a" : 1}), "space not allowed between named argument name and ':'"
assert_syntax_error %({"a": 1, "b" : 2}), "space not allowed between named argument name and ':'"
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3001,20 +3001,22 @@ module Crystal
a_else = parse_expressions
skip_statement_end
check_ident :end
end_location = token_end_location
next_token
break
when Keyword::END
if whens.empty?
unexpected_token "expecting when, else or end"
end
end_location = token_end_location
next_token
break
else
unexpected_token "expecting when, else or end"
end
end

Select.new(whens, a_else)
Select.new(whens, a_else).at_end(end_location)
end

def valid_select_when?(node)
Expand Down

0 comments on commit 673353c

Please sign in to comment.