Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion prism/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ errors:
- PARAMETER_UNEXPECTED_FWD
- PARAMETER_UNEXPECTED_NO_KW
- PARAMETER_WILD_LOOSE_COMMA
- PATTERN_ALTERNATIVE_AFTER_CAPTURE
- PATTERN_ARRAY_MULTIPLE_RESTS
- PATTERN_CAPTURE_DUPLICATE
- PATTERN_CAPTURE_IN_ALTERNATIVE
Expand Down
108 changes: 60 additions & 48 deletions prism/prism.c

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion prism/templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_ERR_PARAMETER_UNEXPECTED_FWD] = { "unexpected `...` in parameters", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_PARAMETER_WILD_LOOSE_COMMA] = { "unexpected `,` in parameters", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_PARAMETER_UNEXPECTED_NO_KW] = { "unexpected **nil; no keywords marker disallowed after keywords", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_PATTERN_ALTERNATIVE_AFTER_CAPTURE] = { "alternative pattern after variable capture", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS] = { "unexpected multiple '*' rest patterns in an array pattern", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_PATTERN_CAPTURE_DUPLICATE] = { "duplicated variable name", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_PATTERN_CAPTURE_IN_ALTERNATIVE] = { "variable capture in alternative pattern", PM_ERROR_LEVEL_SYNTAX },
Expand Down
1 change: 1 addition & 0 deletions test/.excludes-mmtk/TestPatternMatching.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude(:test_alternative_pattern_nested, "Changes here for syntax errors")
1 change: 1 addition & 0 deletions test/.excludes-parsey/TestPatternMatching.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude(:test_alternative_pattern_nested, "Deeply nested captures variables are missing a syntax error")
1 change: 1 addition & 0 deletions test/.excludes/TestPatternMatching.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude(:test_alternative_pattern_nested, "Changes here for syntax errors") if RUBY_DESCRIPTION.include?("+GC")
4 changes: 4 additions & 0 deletions test/prism/errors/pattern-capture-in-alt-array.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 => [a, b] | 2
^ variable capture in alternative pattern
^ variable capture in alternative pattern

3 changes: 3 additions & 0 deletions test/prism/errors/pattern-capture-in-alt-hash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 => { a: b } | 2
^ variable capture in alternative pattern

3 changes: 3 additions & 0 deletions test/prism/errors/pattern-capture-in-alt-name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1 => (2 => b) | 2
^ variable capture in alternative pattern

4 changes: 4 additions & 0 deletions test/prism/errors/pattern-capture-in-alt-top.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 => a | b
^ variable capture in alternative pattern
^ variable capture in alternative pattern

27 changes: 25 additions & 2 deletions test/ruby/test_pattern_matching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,37 @@ def test_alternative_pattern
case 0
in a | 0
end
}, [], /alternative pattern after variable capture/,
}, [], /alternative pattern/,
success: false)

assert_in_out_err(['-c'], %q{
case 0
in 0 | a
end
}, [], /variable capture in alternative pattern/,
}, [], /alternative pattern/,
success: false)
end

def test_alternative_pattern_nested
assert_in_out_err(['-c'], %q{
case 0
in [a] | 1
end
}, [], /alternative pattern/,
success: false)

assert_in_out_err(['-c'], %q{
case 0
in { a: b } | 1
end
}, [], /alternative pattern/,
success: false)

assert_in_out_err(['-c'], %q{
case 0
in [{ a: [{ b: [{ c: }] }] }] | 1
end
}, [], /alternative pattern/,
success: false)
end

Expand Down