duplicated enum item names should result in an error
authorJeff Wang <jjj11x@gmail.com>
Tue, 7 Apr 2020 06:30:11 +0000 (02:30 -0400)
committerJeff Wang <jeffrey.wang@ll.mit.edu>
Tue, 7 Apr 2020 06:30:11 +0000 (02:30 -0400)
frontends/ast/simplify.cc

index b87af0f8c645b2c7986b329cf1240e9ae8f8635a..3fde26fabfb948ce3ec68354349e8cb92bf8639e 100644 (file)
@@ -420,9 +420,10 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
                                current_scope[node->str] = node;
                                for (auto enode : node->children) {
                                        log_assert(enode->type==AST_ENUM_ITEM);
-                                       if (current_scope.count(enode->str) == 0) {
+                                       if (current_scope.count(enode->str) == 0)
                                                current_scope[enode->str] = enode;
-                                       }
+                                       else
+                                               log_file_error(filename, location.first_line, "enum item %s already exists\n", enode->str.c_str());
                                }
                        }
                }