@@ -1908,27 +1908,16 @@ static Type getWithoutProtocolTypeAliases(Type type) {
1908
1908
// /
1909
1909
// / Also see simplifyCurrentTypeWitnesses().
1910
1910
static Type getWitnessTypeForMatching (NormalProtocolConformance *conformance,
1911
- ValueDecl *witness) {
1912
- if (witness->isRecursiveValidation ()) {
1913
- LLVM_DEBUG (llvm::dbgs () << " Recursive validation\n " ;);
1914
- return Type ();
1915
- }
1916
-
1917
- if (witness->isInvalid ()) {
1918
- LLVM_DEBUG (llvm::dbgs () << " Invalid witness\n " ;);
1919
- return Type ();
1920
- }
1921
-
1911
+ ValueDecl *witness, Type type) {
1922
1912
if (!witness->getDeclContext ()->isTypeContext ()) {
1923
1913
// FIXME: Could we infer from 'Self' to make these work?
1924
- return witness-> getInterfaceType () ;
1914
+ return type ;
1925
1915
}
1926
1916
1927
1917
// Retrieve the set of substitutions to be applied to the witness.
1928
1918
Type model =
1929
1919
conformance->getDeclContext ()->mapTypeIntoContext (conformance->getType ());
1930
1920
TypeSubstitutionMap substitutions = model->getMemberSubstitutions (witness);
1931
- Type type = witness->getInterfaceType ()->getReferenceStorageReferent ();
1932
1921
1933
1922
type = getWithoutProtocolTypeAliases (type);
1934
1923
@@ -2082,14 +2071,20 @@ AssociatedTypeInference::inferTypeWitnessesViaAssociatedType(
2082
2071
!witnessHasImplementsAttrForRequiredName (typeDecl, assocType))
2083
2072
continue ;
2084
2073
2085
- // Determine the witness type.
2086
- Type witnessType = getWitnessTypeForMatching (conformance, typeDecl);
2087
- if (!witnessType) continue ;
2074
+ if (typeDecl->isInvalid ()) {
2075
+ LLVM_DEBUG (llvm::dbgs () << " Recursive validation\n " ;);
2076
+ continue ;
2077
+ }
2088
2078
2089
- if (auto witnessMetaType = witnessType->getAs <AnyMetatypeType>())
2090
- witnessType = witnessMetaType->getInstanceType ();
2091
- else
2079
+ if (typeDecl->isRecursiveValidation ()) {
2080
+ LLVM_DEBUG (llvm::dbgs () << " Recursive validation\n " ;);
2092
2081
continue ;
2082
+ }
2083
+
2084
+ // Determine the witness type.
2085
+ Type witnessType = getWitnessTypeForMatching (conformance, typeDecl,
2086
+ typeDecl->getDeclaredInterfaceType ());
2087
+ if (!witnessType) continue ;
2093
2088
2094
2089
if (result.empty ()) {
2095
2090
// If we found at least one default candidate, we must allow for the
@@ -2177,18 +2172,29 @@ AssociatedTypeInference::getPotentialTypeWitnessesByMatchingTypes(ValueDecl *req
2177
2172
InferredAssociatedTypesByWitness inferred;
2178
2173
inferred.Witness = witness;
2179
2174
2180
- // Compute the requirement and witness types we'll use for matching.
2181
- Type fullWitnessType = getWitnessTypeForMatching (conformance, witness);
2182
- if (!fullWitnessType) {
2175
+ auto reqType = removeSelfParam (req, req->getInterfaceType ());
2176
+ Type witnessType;
2177
+
2178
+ if (witness->isRecursiveValidation ()) {
2179
+ LLVM_DEBUG (llvm::dbgs () << " Recursive validation\n " ;);
2183
2180
return inferred;
2184
2181
}
2185
2182
2186
- LLVM_DEBUG (llvm::dbgs () << " Witness type for matching is "
2187
- << fullWitnessType << " \n " ;);
2183
+ if (witness->isInvalid ()) {
2184
+ LLVM_DEBUG (llvm::dbgs () << " Invalid witness\n " ;);
2185
+ return inferred;
2186
+ }
2188
2187
2189
2188
auto setup =
2190
2189
[&]() -> std::tuple<std::optional<RequirementMatch>, Type, Type, Type, Type> {
2191
- fullWitnessType = removeSelfParam (witness, fullWitnessType);
2190
+ // Compute the requirement and witness types we'll use for matching.
2191
+ witnessType = witness->getInterfaceType ()->getReferenceStorageReferent ();
2192
+ witnessType = getWitnessTypeForMatching (conformance, witness, witnessType);
2193
+
2194
+ LLVM_DEBUG (llvm::dbgs () << " Witness type for matching is "
2195
+ << witnessType << " \n " ;);
2196
+
2197
+ witnessType = removeSelfParam (witness, witnessType);
2192
2198
2193
2199
Type reqThrownError;
2194
2200
Type witnessThrownError;
@@ -2211,12 +2217,15 @@ AssociatedTypeInference::getPotentialTypeWitnessesByMatchingTypes(ValueDecl *req
2211
2217
};
2212
2218
2213
2219
reqThrownError = getThrownErrorType (reqASD);
2220
+
2214
2221
witnessThrownError = getThrownErrorType (witnessASD);
2222
+ witnessThrownError = getWitnessTypeForMatching (conformance, witness,
2223
+ witnessThrownError);
2215
2224
}
2216
2225
2217
2226
return std::make_tuple (std::nullopt,
2218
- removeSelfParam (req, req-> getInterfaceType ()) ,
2219
- fullWitnessType, reqThrownError, witnessThrownError);
2227
+ reqType, witnessType ,
2228
+ reqThrownError, witnessThrownError);
2220
2229
};
2221
2230
2222
2231
// / Visits a requirement type to match it to a potential witness for
@@ -2352,7 +2361,7 @@ AssociatedTypeInference::getPotentialTypeWitnessesByMatchingTypes(ValueDecl *req
2352
2361
Type witnessType) -> std::optional<RequirementMatch> {
2353
2362
if (!matchVisitor.match (reqType, witnessType)) {
2354
2363
return RequirementMatch (witness, MatchKind::TypeConflict,
2355
- fullWitnessType );
2364
+ witnessType );
2356
2365
}
2357
2366
2358
2367
return std::nullopt;
@@ -2365,7 +2374,7 @@ AssociatedTypeInference::getPotentialTypeWitnessesByMatchingTypes(ValueDecl *req
2365
2374
return RequirementMatch (witness,
2366
2375
anyRenaming ? MatchKind::RenamedMatch
2367
2376
: MatchKind::ExactMatch,
2368
- fullWitnessType );
2377
+ witnessType );
2369
2378
2370
2379
};
2371
2380
0 commit comments