@@ -291,6 +291,11 @@ class ArchetypeBuilder {
291291 // / be made concrete.
292292 void finalize (SourceLoc loc, bool allowConcreteGenericParams=false );
293293
294+ // / Diagnose any remaining renames.
295+ // /
296+ // / \returns \c true if there were any remaining renames to diagnose.
297+ bool diagnoseRemainingRenames (SourceLoc loc);
298+
294299 // / \brief Resolve the given type to the potential archetype it names.
295300 // /
296301 // / This routine will synthesize nested types as required to refer to a
@@ -409,8 +414,12 @@ class ArchetypeBuilder::PotentialArchetype {
409414 // / the superclass type.
410415 unsigned RecursiveSuperclassType : 1 ;
411416
412- // / Whether we have renamed this (nested) type due to typo correction.
413- unsigned Renamed : 1 ;
417+ // / Whether we have diagnosed a rename.
418+ unsigned DiagnosedRename : 1 ;
419+
420+ // / If we have renamed this (nested) type due to typo correction,
421+ // / the old name.
422+ Identifier OrigName;
414423
415424 // / The equivalence class of this potential archetype.
416425 llvm::TinyPtrVector<PotentialArchetype *> EquivalenceClass;
@@ -421,7 +430,7 @@ class ArchetypeBuilder::PotentialArchetype {
421430 : ParentOrParam(Parent), NameOrAssociatedType(Name), Representative(this ),
422431 IsRecursive (false ), Invalid(false ), SubstitutingConcreteType(false ),
423432 RecursiveConcreteType(false ), RecursiveSuperclassType(false ),
424- Renamed (false )
433+ DiagnosedRename (false )
425434 {
426435 assert (Parent != nullptr && " Not an associated type?" );
427436 EquivalenceClass.push_back (this );
@@ -432,8 +441,8 @@ class ArchetypeBuilder::PotentialArchetype {
432441 : ParentOrParam(Parent), NameOrAssociatedType(AssocType),
433442 Representative(this ), IsRecursive(false ), Invalid(false ),
434443 SubstitutingConcreteType(false ), RecursiveConcreteType(false ),
435- RecursiveSuperclassType(false ), Renamed (false )
436- {
444+ RecursiveSuperclassType(false ), DiagnosedRename (false )
445+ {
437446 assert (Parent != nullptr && " Not an associated type?" );
438447 EquivalenceClass.push_back (this );
439448 }
@@ -443,7 +452,7 @@ class ArchetypeBuilder::PotentialArchetype {
443452 : ParentOrParam(Parent), NameOrAssociatedType(TypeAlias),
444453 Representative(this ), IsRecursive(false ), Invalid(false ),
445454 SubstitutingConcreteType(false ), RecursiveConcreteType(false ),
446- RecursiveSuperclassType(false ), Renamed (false )
455+ RecursiveSuperclassType(false ), DiagnosedRename (false )
447456 {
448457 assert (Parent != nullptr && " Not an associated type?" );
449458 EquivalenceClass.push_back (this );
@@ -457,7 +466,7 @@ class ArchetypeBuilder::PotentialArchetype {
457466 NameOrAssociatedType(Name), Representative(this ), IsRecursive(false ),
458467 Invalid(false ), SubstitutingConcreteType(false ),
459468 RecursiveConcreteType(false ), RecursiveSuperclassType(false ),
460- Renamed (false )
469+ DiagnosedRename (false )
461470 {
462471 EquivalenceClass.push_back (this );
463472 }
@@ -601,15 +610,27 @@ class ArchetypeBuilder::PotentialArchetype {
601610
602611 // / Determine whether this archetype was renamed due to typo
603612 // / correction. If so, \c getName() retrieves the new name.
604- bool wasRenamed () const { return Renamed ; }
613+ bool wasRenamed () const { return !OrigName. empty () ; }
605614
606615 // / Note that this potential archetype was renamed (due to typo
607616 // / correction), providing the new name.
608617 void setRenamed (Identifier newName) {
618+ OrigName = getName ();
609619 NameOrAssociatedType = newName;
610- Renamed = true ;
611620 }
612621
622+ // / For a renamed potential archetype, retrieve the original name.
623+ Identifier getOriginalName () const {
624+ assert (wasRenamed ());
625+ return OrigName;
626+ }
627+
628+ // / Whether we already diagnosed this rename.
629+ bool alreadyDiagnosedRename () const { return DiagnosedRename; }
630+
631+ // / Note that we already diagnosed this rename.
632+ void setAlreadyDiagnosedRename () { DiagnosedRename = true ; }
633+
613634 // / Whether this potential archetype makes a better archetype anchor than
614635 // / the given archetype anchor.
615636 bool isBetterArchetypeAnchor (PotentialArchetype *other) const ;
0 commit comments