Skip to content

Commit

Permalink
fix(compiler)!: Disallow enum variants with parens but no types (#1809)
Browse files Browse the repository at this point in the history
* fix(compiler)!: Disallow enum variants with parens but no types

* Needed to update the message, not remove it

* Update the error message for empty parens
  • Loading branch information
phated authored Apr 8, 2023
1 parent 8a93ebe commit 25e4946
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions compiler/src/parsing/parser.messages
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ program: MODULE UIDENT EOL ENUM UIDENT LBRACE UIDENT LPAREN WHILE
## In state 2, spurious reduction of production lparen -> LPAREN
##

Expected a type or `)` to complete the variant definition.
Expected one or more types to complete the variant definition.

program: MODULE UIDENT EOL ENUM UIDENT LBRACE UIDENT RBRACE COMMA EOL WHILE
##
Expand Down Expand Up @@ -6216,9 +6216,9 @@ program: MODULE UIDENT EOL UIDENT LPAREN WHEN

Expected a comma-separated list of expressions or `)` to complete the constructor.

program: MODULE UIDENT EOL ENUM UIDENT LBRACE UIDENT LPAREN RPAREN YIELD
program: MODULE UIDENT EOL ENUM UIDENT LBRACE UIDENT LPAREN UIDENT RPAREN YIELD
##
## Ends in an error in state: 778.
## Ends in an error in state: 810.
##
## data_constructors -> lbrace lseparated_nonempty_list_inner(comma,data_constructor) . option(comma) rbrace [ SEMI RBRACE EOL EOF COMMA ]
## lseparated_nonempty_list_inner(comma,data_constructor) -> lseparated_nonempty_list_inner(comma,data_constructor) . comma data_constructor [ RBRACE EOL COMMA ]
Expand Down
13 changes: 8 additions & 5 deletions compiler/src/parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ provide_stmt:

data_constructor:
| UIDENT { ConstructorDeclaration.singleton ~loc:(to_loc $loc) (mkstr $loc($1) $1) }
| UIDENT lparen typs? rparen { ConstructorDeclaration.tuple ~loc:(to_loc $loc) (mkstr $loc($1) $1) (Location.mkloc (Option.value ~default:[] $3) (to_loc $loc($3))) }
| UIDENT data_labels { ConstructorDeclaration.record ~loc:(to_loc $loc) (mkstr $loc($1) $1) (Location.mkloc $2 (to_loc $loc($2))) }
| UIDENT data_tuple_body { ConstructorDeclaration.tuple ~loc:(to_loc $loc) (mkstr $loc($1) $1) (Location.mkloc $2 (to_loc $loc($2))) }
| UIDENT data_record_body { ConstructorDeclaration.record ~loc:(to_loc $loc) (mkstr $loc($1) $1) (Location.mkloc $2 (to_loc $loc($2))) }

data_constructors:
| lbrace lseparated_nonempty_list(comma, data_constructor) comma? rbrace { $2 }
Expand All @@ -398,7 +398,10 @@ data_label:
| lid colon typ { LabelDeclaration.mk ~loc:(to_loc $loc) $1 $3 Immutable }
| MUT lid colon typ { LabelDeclaration.mk ~loc:(to_loc $loc) $2 $4 Mutable }

data_labels:
data_tuple_body:
| lparen typs rparen { $2 }

data_record_body:
| lbrace lseparated_nonempty_list(comma, data_label) comma? rbrace { $2 }

id_typ:
Expand All @@ -410,7 +413,7 @@ id_vec:
data_declaration:
| TYPE UIDENT id_vec? equal typ { DataDeclaration.abstract ~loc:(to_loc $loc) (mkstr $loc($2) $2) (Option.value ~default:[] $3) (Some $5) }
| ENUM UIDENT id_vec? data_constructors { DataDeclaration.variant ~loc:(to_loc $loc) (mkstr $loc($2) $2) (Option.value ~default:[] $3) $4 }
| RECORD UIDENT id_vec? data_labels { DataDeclaration.record ~loc:(to_loc $loc) (mkstr $loc($2) $2) (Option.value ~default:[] $3) $4 }
| RECORD UIDENT id_vec? data_record_body { DataDeclaration.record ~loc:(to_loc $loc) (mkstr $loc($2) $2) (Option.value ~default:[] $3) $4 }

unop_expr:
| prefix_op non_assign_expr { Expression.apply ~loc:(to_loc $loc) (mkid_expr $loc($1) [mkstr $loc($1) $1]) [{paa_label=Unlabeled; paa_expr=$2; paa_loc=(to_loc $loc($2))}] }
Expand Down Expand Up @@ -680,7 +683,7 @@ primitive_stmt:
exception_stmt:
| EXCEPTION type_id_str { Exception.singleton ~loc:(to_loc $loc) $2 }
| EXCEPTION type_id_str lparen typs? rparen { Exception.tuple ~loc:(to_loc $loc) $2 (Location.mkloc (Option.value ~default:[] $4) (to_loc $loc($4))) }
| EXCEPTION type_id_str data_labels { Exception.record ~loc:(to_loc $loc) $2 (Location.mkloc $3 (to_loc $loc($3))) }
| EXCEPTION type_id_str data_record_body { Exception.record ~loc:(to_loc $loc) $2 (Location.mkloc $3 (to_loc $loc($3))) }

module_stmt:
| MODULE UIDENT lbrace toplevel_stmts RBRACE { ModuleDeclaration.mk ~loc:(to_loc $loc) (mkstr $loc($2) $2) $4 }
Expand Down

0 comments on commit 25e4946

Please sign in to comment.