From 0c7341be3714ed27c2e9246ecff8784593a11ff1 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 3 Jul 2026 18:10:54 -0700 Subject: [PATCH] Support enum items shadowing type identifiers SystemVerilog allows a declaration in an inner scope to use the same name as a type identifier from an outer scope. This also applies to enum item names. The lexer reports such names as `TYPE_IDENTIFIER` before the enum item has been installed, which made constructs such as: typedef int T; module test; enum { T = 1 } e; endmodule fail in the enum item grammar. Enum item declarations do not have the local type/name ambiguity that exists for variable, net, or parameter declarations. The name in each `enum_name` production is always the enum item name, including the sequence forms like `T[2]` and `T[1:2]`. Use `identifier_name` for these names so they can shadow a visible type identifier. Signed-off-by: Lars-Peter Clausen --- parse.y | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/parse.y b/parse.y index 0803658e8..c7c655661 100644 --- a/parse.y +++ b/parse.y @@ -3242,20 +3242,23 @@ pos_neg_number } ; + /* Enum items are declaration names. Use identifier_name so an enum item can + shadow a visible type identifier without introducing a type/name + ambiguity. */ enum_name - : IDENTIFIER initializer_opt + : identifier_name initializer_opt { perm_string name = lex_strings.make($1); delete[]$1; $$ = make_named_number(@$, name, $2); } - | IDENTIFIER '[' pos_neg_number ']' initializer_opt + | identifier_name '[' pos_neg_number ']' initializer_opt { perm_string name = lex_strings.make($1); long count = check_enum_seq_value(@1, $3, false); $$ = make_named_numbers(@$, name, 0, count-1, $5); delete[]$1; delete $3; } - | IDENTIFIER '[' pos_neg_number ':' pos_neg_number ']' initializer_opt + | identifier_name '[' pos_neg_number ':' pos_neg_number ']' initializer_opt { perm_string name = lex_strings.make($1); $$ = make_named_numbers(@$, name, check_enum_seq_value(@1, $3, true), check_enum_seq_value(@1, $5, true), $7);