@@ -469,13 +469,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
469
469
CalleeCandidateInfo &calleeInfo,
470
470
SourceLoc applyLoc);
471
471
472
- // / Produce diagnostic for failures related to attributes associated with
473
- // / candidate functions/methods e.g. mutability.
474
- bool diagnoseMethodAttributeFailures (ApplyExpr *expr,
475
- ArrayRef<Identifier> argLabels,
476
- bool hasTrailingClosure,
477
- CalleeCandidateInfo &candidates);
478
-
479
472
// / Produce diagnostic for failures related to unfulfilled requirements
480
473
// / of the generic parameters used as arguments.
481
474
bool diagnoseArgumentGenericRequirements (TypeChecker &TC, Expr *callExpr,
@@ -777,14 +770,8 @@ void FailureDiagnosis::diagnoseUnviableLookupResults(
777
770
}
778
771
case MemberLookupResult::UR_MutatingMemberOnRValue:
779
772
case MemberLookupResult::UR_MutatingGetterOnRValue: {
780
- auto diagIDsubelt = diag::cannot_pass_rvalue_mutating_subelement;
781
- auto diagIDmember = diag::cannot_pass_rvalue_mutating;
782
- if (firstProblem == MemberLookupResult::UR_MutatingGetterOnRValue) {
783
- diagIDsubelt = diag::cannot_pass_rvalue_mutating_getter_subelement;
784
- diagIDmember = diag::cannot_pass_rvalue_mutating_getter;
785
- }
786
- assert (baseExpr && " Cannot have a mutation failure without a base" );
787
- AssignmentFailure failure (baseExpr, CS, loc, diagIDsubelt, diagIDmember);
773
+ MutatingMemberRefOnImmutableBase failure (E, CS, choice->getDecl (),
774
+ CS.getConstraintLocator (E));
788
775
(void )failure.diagnose ();
789
776
return ;
790
777
}
@@ -3979,86 +3966,6 @@ bool FailureDiagnosis::diagnoseNilLiteralComparison(
3979
3966
return true ;
3980
3967
}
3981
3968
3982
- bool FailureDiagnosis::diagnoseMethodAttributeFailures (
3983
- swift::ApplyExpr *callExpr, ArrayRef<Identifier> argLabels,
3984
- bool hasTrailingClosure, CalleeCandidateInfo &candidates) {
3985
- auto UDE = dyn_cast<UnresolvedDotExpr>(callExpr->getFn ());
3986
- if (!UDE)
3987
- return false ;
3988
-
3989
- auto argExpr = callExpr->getArg ();
3990
- auto argType = CS.getType (argExpr);
3991
-
3992
- // If type of the argument hasn't been established yet, we can't diagnose.
3993
- if (!argType || isUnresolvedOrTypeVarType (argType))
3994
- return false ;
3995
-
3996
- // Let's filter our candidate list based on that type.
3997
- candidates.filterListArgs (decomposeArgType (argType, argLabels));
3998
-
3999
- if (candidates.closeness == CC_ExactMatch)
4000
- return false ;
4001
-
4002
- // And if filtering didn't give an exact match, such means that problem
4003
- // might be related to function attributes which is best diagnosed by
4004
- // unviable member candidates, if any.
4005
- auto base = UDE->getBase ();
4006
- auto baseType = CS.getType (base);
4007
-
4008
- // This handles following situation:
4009
- // struct S {
4010
- // mutating func f(_ i: Int) {}
4011
- // func f(_ f: Float) {}
4012
- // }
4013
- //
4014
- // Given struct has an overloaded method "f" with a single argument of
4015
- // multiple different types, one of the overloads is marked as
4016
- // "mutating", which means it can only be applied on LValue base type.
4017
- // So when struct is used like this:
4018
- //
4019
- // let answer: Int = 42
4020
- // S().f(answer)
4021
- //
4022
- // Constraint system generator is going to pick `f(_ f: Float)` as
4023
- // only possible overload candidate because "base" of the call is immutable
4024
- // and contextual information about argument type is not available yet.
4025
- // Such leads to incorrect contextual conversion failure diagnostic because
4026
- // type of the argument is going to resolved as (Int) no matter what.
4027
- // To workaround that fact and improve diagnostic of such cases we are going
4028
- // to try and collect all unviable candidates for a given call and check if
4029
- // at least one of them matches established argument type before even trying
4030
- // to re-check argument expression.
4031
- auto results = CS.performMemberLookup (
4032
- ConstraintKind::ValueMember, UDE->getName (), baseType,
4033
- UDE->getFunctionRefKind (), CS.getConstraintLocator (UDE),
4034
- /* includeInaccessibleMembers=*/ false );
4035
-
4036
- if (results.UnviableCandidates .empty ())
4037
- return false ;
4038
-
4039
- SmallVector<OverloadChoice, 2 > choices;
4040
- for (auto &unviable : results.UnviableCandidates )
4041
- choices.push_back (OverloadChoice (baseType, unviable.getDecl (),
4042
- UDE->getFunctionRefKind ()));
4043
-
4044
- CalleeCandidateInfo unviableCandidates (baseType, choices, hasTrailingClosure,
4045
- CS);
4046
-
4047
- // Filter list of the unviable candidates based on the
4048
- // already established type of the argument expression.
4049
- unviableCandidates.filterListArgs (decomposeArgType (argType, argLabels));
4050
-
4051
- // If one of the unviable candidates matches arguments exactly,
4052
- // that means that actual problem is related to function attributes.
4053
- if (unviableCandidates.closeness == CC_ExactMatch) {
4054
- diagnoseUnviableLookupResults (results, UDE, baseType, base, UDE->getName (),
4055
- UDE->getNameLoc (), UDE->getLoc ());
4056
- return true ;
4057
- }
4058
-
4059
- return false ;
4060
- }
4061
-
4062
3969
bool FailureDiagnosis::diagnoseArgumentGenericRequirements (
4063
3970
TypeChecker &TC, Expr *callExpr, Expr *fnExpr, Expr *argExpr,
4064
3971
CalleeCandidateInfo &candidates, ArrayRef<Identifier> argLabels) {
@@ -4811,14 +4718,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
4811
4718
callExpr->getArg (), argLabels))
4812
4719
return true ;
4813
4720
4814
- // There might be a candidate with correct argument types but it's not
4815
- // used by constraint solver because it doesn't have correct attributes,
4816
- // let's try to diagnose such situation there right before type checking
4817
- // argument expression, because that would overwrite original argument types.
4818
- if (diagnoseMethodAttributeFailures (callExpr, argLabels, hasTrailingClosure,
4819
- calleeInfo))
4820
- return true ;
4821
-
4822
4721
Type argType; // argument list, if known.
4823
4722
if (auto FTy = fnType->getAs <AnyFunctionType>()) {
4824
4723
argType = FunctionType::composeInput (CS.getASTContext (), FTy->getParams (),
0 commit comments