@@ -9284,38 +9284,43 @@ auto Parser::parse_class_head(ClassHead& classHead) -> bool {
92849284    }
92859285  }
92869286
9287-   const  Identifier* id  = nullptr ;
9287+   const  Identifier* identifier  = nullptr ;
92889288  SourceLocation location;
92899289  bool  isTemplateSpecialization = false ;
92909290  if  (const  auto  simpleName = ast_cast<NameIdAST>(classHead.name )) {
92919291    location = simpleName->identifierLoc ;
9292-     id  = simpleName->identifier ;
9292+     identifier  = simpleName->identifier ;
92939293  } else  if  (const  auto  t = ast_cast<SimpleTemplateIdAST>(classHead.name )) {
92949294    location = t->firstSourceLocation ();
92959295    isTemplateSpecialization = true ;
9296-     id  = t->identifier ;
9296+     identifier  = t->identifier ;
92979297  } else  {
92989298    location = currentLocation ();
92999299  }
93009300
93019301  ClassSymbol* classSymbol = nullptr ;
93029302
9303-   if  (id && !isTemplateSpecialization) {
9304-     for  (auto  previousClass : scope_->find (id) | views::classes) {
9305-       if  (previousClass->isComplete ()) {
9306-         parse_error (classHead.name ->firstSourceLocation (),
9307-                     " class name already declared"  );
9308-       } else  {
9309-         classSymbol = previousClass;
9303+   if  (identifier) {
9304+     if  (!is_class_declaration) {
9305+       auto  symbol = symbol_cast<ClassSymbol>(Lookup{scope_}(identifier));
9306+       classSymbol = symbol;
9307+     } else  if  (!isTemplateSpecialization) {
9308+       for  (auto  previousClass : scope_->find (identifier) | views::classes) {
9309+         if  (previousClass->isComplete ()) {
9310+           parse_error (classHead.name ->firstSourceLocation (),
9311+                       " class name already declared"  );
9312+         } else  {
9313+           classSymbol = previousClass;
9314+         }
9315+         break ;
93109316      }
9311-       break ;
93129317    }
93139318  }
93149319
93159320  if  (!classSymbol) {
93169321    classSymbol = control_->newClassSymbol (scope_, location);
93179322    classSymbol->setIsUnion (isUnion);
9318-     classSymbol->setName (id );
9323+     classSymbol->setName (identifier );
93199324
93209325    std::invoke (DeclareSymbol{this , scope_}, classSymbol);
93219326  }
0 commit comments