Skip to content

Commit 94480d9

Browse files
asteriteRX14
authored andcommitted
Syntax: fix incorrect handling of "%w(" (#5241)
1 parent 3c7ed65 commit 94480d9

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

spec/compiler/parser/parser_spec.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,9 @@ describe "Parser" do
15981598
assert_syntax_error %(case x; when /x/; 2; when /x/; end), "duplicate when /x/ in case"
15991599
assert_syntax_error %(case x; when X; 2; when X; end), "duplicate when X in case"
16001600

1601+
assert_syntax_error "%w(", "Unterminated String array literal"
1602+
assert_syntax_error "%i(", "Unterminated Symbol array literal"
1603+
16011604
it "gets corrects of ~" do
16021605
node = Parser.parse("\n ~1")
16031606
loc = node.location.not_nil!

src/compiler/crystal/syntax/lexer.cr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,11 @@ module Crystal
24382438
next_char
24392439
end
24402440

2441+
if start == current_pos
2442+
@token.type = :EOF
2443+
return @token
2444+
end
2445+
24412446
@token.type = :STRING
24422447
@token.value = string_range(start)
24432448
set_token_raw_from_start(start)

src/compiler/crystal/syntax/parser.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,8 @@ module Crystal
20492049
when :STRING_ARRAY_END
20502050
next_token
20512051
break
2052-
when :EOF
2053-
raise "Unterminated symbol array literal"
2052+
else
2053+
raise "Unterminated #{elements_type} array literal"
20542054
end
20552055
end
20562056

0 commit comments

Comments
 (0)