diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index c97e5c6d6712..f4c6cf7799cf 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -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 ':'" diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index b73ee2afbf68..2b3727d681c5 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -3001,12 +3001,14 @@ 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 @@ -3014,7 +3016,7 @@ module Crystal end end - Select.new(whens, a_else) + Select.new(whens, a_else).at_end(end_location) end def valid_select_when?(node)