Skip to content

Commit

Permalink
Fix <rdar://problem/22108559> QoI: Confusing error message when calli…
Browse files Browse the repository at this point in the history
…ng an instance method as a class method
  • Loading branch information
lattner committed Dec 11, 2015
1 parent d47cded commit a2d9b10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions lib/Sema/CSDiag.cpp
Expand Up @@ -1700,11 +1700,7 @@ bool CalleeCandidateInfo::diagnoseAnyStructuralArgumentError(Expr *fnExpr,
// here.
if (size() != 1) return false;

// We only handle structural errors here.
if (closeness != CC_ArgumentLabelMismatch &&
closeness != CC_ArgumentCountMismatch)
return false;


auto args = decomposeArgParamType(argExpr->getType());
auto params = decomposeArgParamType(candidates[0].getArgumentType());

Expand All @@ -1731,6 +1727,11 @@ bool CalleeCandidateInfo::diagnoseAnyStructuralArgumentError(Expr *fnExpr,
}
}

// We only handle structural errors here.
if (closeness != CC_ArgumentLabelMismatch &&
closeness != CC_ArgumentCountMismatch)
return false;

SmallVector<Identifier, 4> correctNames;
unsigned OOOArgIdx = ~0U, OOOPrevArgIdx = ~0U;
unsigned extraArgIdx = ~0U, missingParamIdx = ~0U;
Expand Down Expand Up @@ -3266,6 +3267,15 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
if (candidates.size() == 1 && !argType)
argType = candidates[0].getArgumentType();
}

// If our candidates are instance members at curry level #0, then the argument
// being provided is the receiver type for the instance. We produce better
// diagnostics when we don't force the self type down.
if (argType && !candidates.empty() &&
candidates[0].decl->isInstanceMember() && candidates[0].level == 0 &&
!isa<SubscriptDecl>(candidates[0].decl))
argType = Type();


// FIXME: This should all just be a matter of getting type type of the
// sub-expression, but this doesn't work well when typeCheckChildIndependently
Expand Down
4 changes: 2 additions & 2 deletions test/Constraints/diagnostics.swift
Expand Up @@ -339,7 +339,7 @@ c.method2(1.0)(b: 2.0) // expected-error {{cannot convert value of type 'Double'
CurriedClass.method1(c)()
_ = CurriedClass.method1(c)
CurriedClass.method1(c)(1) // expected-error {{argument passed to call that takes no arguments}}
CurriedClass.method1(2.0)(1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'CurriedClass'}}
CurriedClass.method1(2.0)(1) // expected-error {{use of instance member 'method1' on type 'CurriedClass'; did you mean to use a value of type 'CurriedClass' instead?}}

CurriedClass.method2(c)(32)(b: 1)
_ = CurriedClass.method2(c)
Expand Down Expand Up @@ -380,7 +380,7 @@ CurriedClass.m1(2, b: 42) // expected-error {{use of instance member 'm1' on t


// <rdar://problem/22108559> QoI: Confusing error message when calling an instance method as a class method
CurriedClass.m2(12) // expected-error {{cannot convert value of type 'Int' to expected argument type 'CurriedClass'}}
CurriedClass.m2(12) // expected-error {{use of instance member 'm2' on type 'CurriedClass'; did you mean to use a value of type 'CurriedClass' instead?}}



Expand Down

0 comments on commit a2d9b10

Please sign in to comment.