Skip to content

Commit 856220c

Browse files
makenowjustRX14
authored andcommittedJan 2, 2018
Fix to parse regex in default argument (#5481)
1 parent d7273c7 commit 856220c

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed
 

Diff for: ‎spec/compiler/parser/parser_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ describe "Parser" do
867867
it_parses "a()/3", Call.new("a".call, "/", 3.int32)
868868
it_parses "a() /3", Call.new("a".call, "/", 3.int32)
869869
it_parses "a.b() /3", Call.new(Call.new("a".call, "b"), "/", 3.int32)
870+
it_parses "def foo(x = / /); end", Def.new("foo", [Arg.new("x", regex(" "))])
870871

871872
it_parses "1 =~ 2", Call.new(1.int32, "=~", 2.int32)
872873
it_parses "1.=~(2)", Call.new(1.int32, "=~", 2.int32)

Diff for: ‎src/compiler/crystal/syntax/parser.cr

+1
Original file line numberDiff line numberDiff line change
@@ -3446,6 +3446,7 @@ module Crystal
34463446
raise "splat argument can't have default value", @token if splat
34473447
raise "double splat argument can't have default value", @token if double_splat
34483448

3449+
slash_is_regex!
34493450
next_token_skip_space_or_newline
34503451

34513452
case @token.type

0 commit comments

Comments
 (0)