@@ -1775,6 +1775,7 @@ static void concretizeNestedTypeFromConcreteParent(
1775
1775
1776
1776
PotentialArchetype *PotentialArchetype::getNestedType (
1777
1777
Identifier nestedName,
1778
+ ArchetypeResolutionKind kind,
1778
1779
GenericSignatureBuilder &builder) {
1779
1780
// If we already have a nested type with this name, return it.
1780
1781
auto known = NestedTypes.find (nestedName);
@@ -1783,8 +1784,7 @@ PotentialArchetype *PotentialArchetype::getNestedType(
1783
1784
1784
1785
// Retrieve the nested archetype anchor, which is the best choice (so far)
1785
1786
// for this nested type.
1786
- return getNestedArchetypeAnchor (nestedName, builder,
1787
- ArchetypeResolutionKind::AlwaysPartial);
1787
+ return getNestedArchetypeAnchor (nestedName, builder, kind);
1788
1788
}
1789
1789
1790
1790
PotentialArchetype *PotentialArchetype::getNestedType (
@@ -1916,7 +1916,7 @@ PotentialArchetype *PotentialArchetype::getNestedArchetypeAnchor(
1916
1916
1917
1917
auto rep = getRepresentative ();
1918
1918
if (rep != this ) {
1919
- auto existingPA = rep->getNestedType (name, builder);
1919
+ auto existingPA = rep->getNestedType (name, kind, builder);
1920
1920
1921
1921
auto sameNamedSource =
1922
1922
RequirementSource::forNestedTypeNameMatch (existingPA);
@@ -2040,7 +2040,7 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
2040
2040
if (assocType)
2041
2041
existingPA = rep->getNestedType (assocType, builder);
2042
2042
else
2043
- existingPA = rep->getNestedType (name , builder);
2043
+ existingPA = rep->getNestedType (concreteDecl , builder);
2044
2044
}
2045
2045
}
2046
2046
@@ -2304,7 +2304,10 @@ void ArchetypeType::resolveNestedType(
2304
2304
auto parentPA =
2305
2305
builder.resolveArchetype (interfaceType,
2306
2306
ArchetypeResolutionKind::CompleteWellFormed);
2307
- auto memberPA = parentPA->getNestedType (nested.first , builder);
2307
+ auto memberPA = parentPA->getNestedType (
2308
+ nested.first ,
2309
+ ArchetypeResolutionKind::CompleteWellFormed,
2310
+ builder);
2308
2311
auto result = memberPA->getTypeInContext (builder, genericEnv);
2309
2312
assert (!nested.second ||
2310
2313
nested.second ->isEqual (result) ||
@@ -2903,13 +2906,13 @@ ConstraintResult GenericSignatureBuilder::addConformanceRequirement(
2903
2906
2904
2907
// / Perform typo correction on the given nested type, producing the
2905
2908
// / corrected name (if successful).
2906
- static Identifier typoCorrectNestedType (
2907
- GenericSignatureBuilder::PotentialArchetype *pa) {
2909
+ static AssociatedTypeDecl * typoCorrectNestedType (
2910
+ GenericSignatureBuilder::PotentialArchetype *pa) {
2908
2911
StringRef name = pa->getNestedName ().str ();
2909
2912
2910
2913
// Look through all of the associated types of all of the protocols
2911
2914
// to which the parent conforms.
2912
- llvm::SmallVector<Identifier , 2 > bestMatches;
2915
+ llvm::SmallVector<AssociatedTypeDecl * , 2 > bestMatches;
2913
2916
unsigned bestEditDistance = UINT_MAX;
2914
2917
unsigned maxScore = (name.size () + 1 ) / 3 ;
2915
2918
for (auto proto : pa->getParent ()->getConformsTo ()) {
@@ -2927,21 +2930,21 @@ static Identifier typoCorrectNestedType(
2927
2930
bestMatches.clear ();
2928
2931
}
2929
2932
if (dist == bestEditDistance)
2930
- bestMatches.push_back (assocType-> getName () );
2933
+ bestMatches.push_back (assocType);
2931
2934
}
2932
2935
}
2933
2936
2934
2937
// FIXME: Look through the superclass.
2935
2938
2936
2939
// If we didn't find any matches at all, fail.
2937
2940
if (bestMatches.empty ())
2938
- return Identifier () ;
2941
+ return nullptr ;
2939
2942
2940
2943
// Make sure that we didn't find more than one match at the best
2941
2944
// edit distance.
2942
2945
for (auto other : llvm::makeArrayRef (bestMatches).slice (1 )) {
2943
2946
if (other != bestMatches.front ())
2944
- return Identifier () ;
2947
+ return nullptr ;
2945
2948
}
2946
2949
2947
2950
return bestMatches.front ();
@@ -2976,8 +2979,8 @@ ConstraintResult GenericSignatureBuilder::resolveUnresolvedType(
2976
2979
return ConstraintResult::Unresolved;
2977
2980
2978
2981
// Try to typo correct to a nested type name.
2979
- Identifier correction = typoCorrectNestedType (pa);
2980
- if (correction. empty () ) {
2982
+ auto correction = typoCorrectNestedType (pa);
2983
+ if (! correction) {
2981
2984
pa->setInvalid ();
2982
2985
return ConstraintResult::Conflicting;
2983
2986
}
@@ -2988,8 +2991,7 @@ ConstraintResult GenericSignatureBuilder::resolveUnresolvedType(
2988
2991
2989
2992
// Resolve the associated type and merge the potential archetypes.
2990
2993
auto replacement = pa->getParent ()->getNestedType (correction, *this );
2991
- pa->resolveAssociatedType (replacement->getResolvedAssociatedType (),
2992
- *this );
2994
+ pa->resolveAssociatedType (correction, *this );
2993
2995
addSameTypeRequirement (pa, replacement,
2994
2996
RequirementSource::forNestedTypeNameMatch (pa),
2995
2997
UnresolvedHandlingKind::GenerateConstraints);
0 commit comments