Skip to content

Commit fe78661

Browse files
akzhanMartin Verzilli
authored andcommitted
Fixes #4361 wrong error message: unexpected token: end
Replace "expecting when, else or end" with "expecting when or else".
1 parent 6930423 commit fe78661

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

spec/compiler/parser/parser_spec.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ describe "Parser" do
917917
it_parses "case a\nwhen b\n1 / 2\nelse\n1 / 2\nend", Case.new("a".call, [When.new(["b".call] of ASTNode, Call.new(1.int32, "/", 2.int32))], Call.new(1.int32, "/", 2.int32))
918918
it_parses "case a\nwhen b\n/ /\n\nelse\n/ /\nend", Case.new("a".call, [When.new(["b".call] of ASTNode, RegexLiteral.new(StringLiteral.new(" ")))], RegexLiteral.new(StringLiteral.new(" ")))
919919
assert_syntax_error "case {1, 2}; when {3}; 4; end", "wrong number of tuple elements (given 1, expected 2)", 1, 19
920+
assert_syntax_error "case 1; end", "unexpected token: end (expecting when or else)", 1, 9
920921

921922
it_parses "select\nwhen foo\n2\nend", Select.new([Select::When.new("foo".call, 2.int32)])
922923
it_parses "select\nwhen foo\n2\nwhen bar\n4\nend", Select.new([Select::When.new("foo".call, 2.int32), Select::When.new("bar".call, 4.int32)])

src/compiler/crystal/syntax/parser.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2391,7 +2391,7 @@ module Crystal
23912391
break
23922392
when :end
23932393
if whens.empty?
2394-
unexpected_token @token.to_s, "expecting when, else or end"
2394+
unexpected_token @token.to_s, "expecting when or else"
23952395
end
23962396
next_token
23972397
break

0 commit comments

Comments
 (0)