@@ -468,13 +468,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
468
468
CalleeCandidateInfo &calleeInfo,
469
469
SourceLoc applyLoc);
470
470
471
- // / Produce diagnostic for failures related to unfulfilled requirements
472
- // / of the generic parameters used as arguments.
473
- bool diagnoseArgumentGenericRequirements (TypeChecker &TC, Expr *callExpr,
474
- Expr *fnExpr, Expr *argExpr,
475
- CalleeCandidateInfo &candidates,
476
- ArrayRef<Identifier> argLabels);
477
-
478
471
bool diagnoseMemberFailures (
479
472
Expr *E, Expr *baseEpxr, ConstraintKind lookupKind, DeclName memberName,
480
473
FunctionRefKind funcRefKind, ConstraintLocator *locator,
@@ -3065,185 +3058,6 @@ bool FailureDiagnosis::diagnoseNilLiteralComparison(
3065
3058
return true ;
3066
3059
}
3067
3060
3068
- bool FailureDiagnosis::diagnoseArgumentGenericRequirements (
3069
- TypeChecker &TC, Expr *callExpr, Expr *fnExpr, Expr *argExpr,
3070
- CalleeCandidateInfo &candidates, ArrayRef<Identifier> argLabels) {
3071
- if (candidates.closeness != CC_ExactMatch || candidates.size () != 1 )
3072
- return false ;
3073
-
3074
- AbstractFunctionDecl *AFD = nullptr ;
3075
- if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
3076
- AFD = dyn_cast<AbstractFunctionDecl>(DRE->getDecl ());
3077
- } else if (auto *candidate = candidates[0 ].getDecl ()) {
3078
- AFD = dyn_cast<AbstractFunctionDecl>(candidate);
3079
- }
3080
-
3081
- if (!AFD || !AFD->getGenericSignature () || !AFD->hasInterfaceType ())
3082
- return false ;
3083
-
3084
- auto env = AFD->getGenericEnvironment ();
3085
- if (!env)
3086
- return false ;
3087
-
3088
- auto const &candidate = candidates.candidates [0 ];
3089
-
3090
- if (!candidate.hasParameters ())
3091
- return false ;
3092
-
3093
- auto params = candidate.getParameters ();
3094
- auto paramInfo = candidate.getParameterListInfo (params);
3095
- auto args = decomposeArgType (CS.getType (argExpr), argLabels);
3096
-
3097
- SmallVector<ParamBinding, 4 > bindings;
3098
- MatchCallArgumentListener listener;
3099
- if (matchCallArguments (args, params, paramInfo,
3100
- candidates.hasTrailingClosure ,
3101
- /* allowFixes=*/ false , listener, bindings))
3102
- return false ;
3103
-
3104
- TypeSubstitutionMap substitutions;
3105
- // First, let's collect all of the archetypes and their substitutions,
3106
- // that's going to help later on if there are cross-archetype
3107
- // requirements e.g. <A, B where A.Element == B.Element>.
3108
- for (unsigned i = 0 , e = bindings.size (); i != e; ++i) {
3109
- auto param = params[i];
3110
- auto paramType = param.getPlainType ();
3111
-
3112
- auto archetype = paramType->getAs <ArchetypeType>();
3113
- if (!archetype)
3114
- continue ;
3115
-
3116
- // Bindings specify the arguments that source the parameter. The only case
3117
- // this returns a non-singular value is when there are varargs in play.
3118
- for (auto argNo : bindings[i]) {
3119
- auto argType = args[argNo]
3120
- .getOldType ()
3121
- ->getWithoutSpecifierType ();
3122
-
3123
- if (auto *archetype = argType->getAs <ArchetypeType>()) {
3124
- auto interfaceTy = archetype->getInterfaceType ();
3125
- if (auto *paramTy = interfaceTy->getAs <GenericTypeParamType>()) {
3126
- diagnoseAmbiguousGenericParameter (paramTy, fnExpr);
3127
- return true ;
3128
- }
3129
- }
3130
-
3131
- if (isUnresolvedOrTypeVarType (argType) || argType->hasError ())
3132
- return false ;
3133
-
3134
- // Record substitution from generic parameter to the argument type.
3135
- substitutions[archetype->getInterfaceType ()->getCanonicalType ()
3136
- ->castTo <SubstitutableType>()] = argType;
3137
- }
3138
- }
3139
-
3140
- if (substitutions.empty ())
3141
- return false ;
3142
-
3143
- class RequirementsListener : public GenericRequirementsCheckListener {
3144
- ConstraintSystem &CS;
3145
- AbstractFunctionDecl *Candidate;
3146
- TypeSubstitutionFn Substitutions;
3147
-
3148
- Expr *CallExpr;
3149
- Expr *FnExpr;
3150
- Expr *ArgExpr;
3151
-
3152
- public:
3153
- RequirementsListener (ConstraintSystem &cs, AbstractFunctionDecl *AFD,
3154
- TypeSubstitutionFn subs,
3155
- Expr *callExpr, Expr *fnExpr, Expr *argExpr)
3156
- : CS(cs), Candidate(AFD), Substitutions(subs), CallExpr(callExpr),
3157
- FnExpr (fnExpr), ArgExpr(argExpr) {}
3158
-
3159
- bool shouldCheck (RequirementKind kind, Type first, Type second) override {
3160
- // This means that we have encountered requirement which references
3161
- // generic parameter not used in the arguments, we can't diagnose it here.
3162
- return !(first->hasTypeParameter () || first->isTypeVariableOrMember ());
3163
- }
3164
-
3165
- bool diagnoseUnsatisfiedRequirement (
3166
- const Requirement &req, Type first, Type second,
3167
- ArrayRef<ParentConditionalConformance> parents) override {
3168
- Diag<Type, Type, Type, Type, StringRef> note;
3169
- switch (req.getKind ()) {
3170
- case RequirementKind::Conformance:
3171
- case RequirementKind::Layout:
3172
- return false ;
3173
-
3174
- case RequirementKind::Superclass:
3175
- note = diag::candidate_types_inheritance_requirement;
3176
- break ;
3177
-
3178
- case RequirementKind::SameType:
3179
- note = diag::candidate_types_equal_requirement;
3180
- break ;
3181
- }
3182
-
3183
- TypeChecker &TC = CS.TC ;
3184
- SmallVector<char , 8 > scratch;
3185
- auto overloadName = Candidate->getFullName ().getString (scratch);
3186
-
3187
- if (isa<BinaryExpr>(CallExpr) && isa<TupleExpr>(ArgExpr)) {
3188
- auto argTuple = cast<TupleExpr>(ArgExpr);
3189
- auto lhsExpr = argTuple->getElement (0 ),
3190
- rhsExpr = argTuple->getElement (1 );
3191
- auto lhsType = CS.getType (lhsExpr)->getRValueType ();
3192
- auto rhsType = CS.getType (rhsExpr)->getRValueType ();
3193
-
3194
- TC.diagnose (FnExpr->getLoc (), diag::cannot_apply_binop_to_args,
3195
- overloadName, lhsType, rhsType)
3196
- .highlight (lhsExpr->getSourceRange ())
3197
- .highlight (rhsExpr->getSourceRange ());
3198
- } else if (isa<PrefixUnaryExpr>(CallExpr) ||
3199
- isa<PostfixUnaryExpr>(CallExpr)) {
3200
- TC.diagnose (ArgExpr->getLoc (), diag::cannot_apply_unop_to_arg,
3201
- overloadName, CS.getType (ArgExpr));
3202
- } else {
3203
- bool isInitializer = isa<ConstructorDecl>(Candidate);
3204
-
3205
- SmallVector<AnyFunctionType::Param, 8 > Params;
3206
- AnyFunctionType::decomposeInput (CS.getType (ArgExpr), Params);
3207
- TC.diagnose (ArgExpr->getLoc (), diag::cannot_call_with_params,
3208
- overloadName, AnyFunctionType::getParamListAsString (Params),
3209
- isInitializer);
3210
- }
3211
-
3212
- auto rawFirstType = req.getFirstType ();
3213
- auto rawSecondType = req.getSecondType ();
3214
- auto *genericSig = Candidate->getGenericSignature ();
3215
-
3216
- TC.diagnose (Candidate, note, first, second,
3217
- rawFirstType, rawSecondType,
3218
- TypeChecker::gatherGenericParamBindingsText (
3219
- {rawFirstType, rawSecondType},
3220
- genericSig->getGenericParams (),
3221
- Substitutions));
3222
-
3223
- ParentConditionalConformance::diagnoseConformanceStack (
3224
- TC.Diags , Candidate->getLoc (), parents);
3225
-
3226
- return true ;
3227
- }
3228
- };
3229
-
3230
- auto substitutionFn = QueryTypeSubstitutionMap{substitutions};
3231
- RequirementsListener genericReqListener (CS, AFD, substitutionFn,
3232
- callExpr, fnExpr, argExpr);
3233
-
3234
- auto result = TC.checkGenericArguments(
3235
- AFD, callExpr->getLoc (), fnExpr->getLoc(), AFD->getInterfaceType(),
3236
- env->getGenericSignature()->getGenericParams(),
3237
- env->getGenericSignature()->getRequirements(),
3238
- substitutionFn,
3239
- LookUpConformanceInModule{AFD->getParentModule ()},
3240
- ConformanceCheckFlags::SuppressDependencyTracking, &genericReqListener);
3241
-
3242
- // Note: If result is RequirementCheckResult::SubstitutionFailure, we did
3243
- // not emit a diagnostic, so we must return false in that case.
3244
- return result == RequirementCheckResult::Failure;
3245
- }
3246
-
3247
3061
static bool diagnoseClosureExplicitParameterMismatch (
3248
3062
ConstraintSystem &CS, SourceLoc loc,
3249
3063
ArrayRef<AnyFunctionType::Param> params,
@@ -3980,10 +3794,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
3980
3794
}
3981
3795
}
3982
3796
3983
- if (diagnoseArgumentGenericRequirements (CS.TC , callExpr, fnExpr, argExpr,
3984
- calleeInfo, argLabels))
3985
- return true ;
3986
-
3987
3797
if (isContextualConversionFailure (argTuple))
3988
3798
return false ;
3989
3799
@@ -4053,15 +3863,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
4053
3863
return true ;
4054
3864
}
4055
3865
4056
- // If all of the arguments are a perfect match, let's check if there
4057
- // are problems with requirements placed on generic parameters, because
4058
- // CalleeCandidateInfo validates only conformance of the parameters
4059
- // to their protocol types (if any) but it doesn't check additional
4060
- // requirements placed on e.g. nested types or between parameters.
4061
- if (diagnoseArgumentGenericRequirements (CS.TC , callExpr, fnExpr, argExpr,
4062
- calleeInfo, argLabels))
4063
- return true ;
4064
-
4065
3866
// If we have a failure where closeness is an exact match, but there is
4066
3867
// still a failed argument, it is because one (or more) of the arguments
4067
3868
// types are unresolved.
0 commit comments