Skip to content

Commit

Permalink
Fixes #4361 wrong error message: unexpected token: end
Browse files Browse the repository at this point in the history
Replace "expecting when, else or end" with "expecting when or else".
akzhan authored and Martin Verzilli committed May 17, 2017
1 parent 6930423 commit fe78661
Showing 2 changed files with 2 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
@@ -917,6 +917,7 @@ describe "Parser" do
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))
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(" ")))
assert_syntax_error "case {1, 2}; when {3}; 4; end", "wrong number of tuple elements (given 1, expected 2)", 1, 19
assert_syntax_error "case 1; end", "unexpected token: end (expecting when or else)", 1, 9

it_parses "select\nwhen foo\n2\nend", Select.new([Select::When.new("foo".call, 2.int32)])
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)])
2 changes: 1 addition & 1 deletion src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
@@ -2391,7 +2391,7 @@ module Crystal
break
when :end
if whens.empty?
unexpected_token @token.to_s, "expecting when, else or end"
unexpected_token @token.to_s, "expecting when or else"
end
next_token
break

0 comments on commit fe78661

Please sign in to comment.