Skip to content

Commit

Permalink
Merge pull request #3084 from ruby/label-in-parentheses
Browse files Browse the repository at this point in the history
Disallow label in parentheses
  • Loading branch information
kddnewton authored Sep 25, 2024
2 parents 4daf58f + b624e09 commit 7753853
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 98 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ errors:
- UNEXPECTED_BLOCK_ARGUMENT
- UNEXPECTED_INDEX_BLOCK
- UNEXPECTED_INDEX_KEYWORDS
- UNEXPECTED_LABEL
- UNEXPECTED_MULTI_WRITE
- UNEXPECTED_RANGE_OPERATOR
- UNEXPECTED_SAFE_NAVIGATION
Expand Down
188 changes: 93 additions & 95 deletions src/prism.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,13 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_ERR_TERNARY_COLON] = { "expected a `:` after the true expression of a ternary operator", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_TERNARY_EXPRESSION_FALSE] = { "expected an expression after `:` in the ternary operator", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_TERNARY_EXPRESSION_TRUE] = { "expected an expression after `?` in the ternary operator", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNDEF_ARGUMENT] = { "invalid argument being passed to `undef`; expected a bare word, constant, or symbol argument", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNARY_RECEIVER] = { "unexpected %s, expected a receiver for unary `%c`", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNARY_DISALLOWED] = { "unexpected %s; unary calls are not allowed in this context", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNDEF_ARGUMENT] = { "invalid argument being passed to `undef`; expected a bare word, constant, or symbol argument", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_BLOCK_ARGUMENT] = { "block argument should not be given", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_INDEX_BLOCK] = { "unexpected block arg given in index assignment; blocks are not allowed in index assignment expressions", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_INDEX_KEYWORDS] = { "unexpected keyword arg given in index assignment; keywords are not allowed in index assignment expressions", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_LABEL] = { "unexpected label", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_MULTI_WRITE] = { "unexpected multiple assignment; multiple assignment is not allowed in this context", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_RANGE_OPERATOR] = { "unexpected range operator; .. and ... are non-associative and cannot be chained", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_UNEXPECTED_SAFE_NAVIGATION] = { "&. inside multiple assignment destination", PM_ERROR_LEVEL_SYNTAX },
Expand Down
3 changes: 3 additions & 0 deletions test/prism/errors/label_in_parentheses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
("a":)
^~~~ unexpected label

2 changes: 1 addition & 1 deletion test/prism/errors/symbol_in_hash.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{x:'y':}
^~ unexpected label terminator, expected a string literal terminator
^~~~ unexpected label

2 changes: 1 addition & 1 deletion test/prism/errors/symbol_in_keyword_parameter.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def foo(x:'y':); end
^~ unexpected label terminator, expected a string literal terminator
^~~~ unexpected label

0 comments on commit 7753853

Please sign in to comment.