Skip to content

[CSDiag] Don't increase candidate curry level if base is ignored #19934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Sema/CalleeCandidateInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,16 @@ void CalleeCandidateInfo::collectCalleeCandidates(Expr *fn,
if (auto UDE = dyn_cast<UnresolvedDotExpr>(fn)) {
declName = UDE->getName().getBaseName().userFacingName();
uncurryLevel = 1;


// If base is a module or metatype, this is just a simple
// reference so its curry level should be 0.
if (auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase())) {
if (auto baseType = DRE->getType())
uncurryLevel =
(baseType->is<ModuleType>() || baseType->is<AnyMetatypeType>()) ? 0
: 1;
}

// If we actually resolved the member to use, return it.
auto loc = CS.getConstraintLocator(UDE, ConstraintLocator::Member);
if (auto *member = CS.findResolvedMemberRef(loc)) {
Expand Down
22 changes: 22 additions & 0 deletions test/Constraints/rdar45242032.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-typecheck-verify-swift -module-name M

protocol P {
var v: String { get }
}

func foo(bar: [P], baz: [P]) {
// expected-note@-1 {{'foo(bar:baz:)' declared here}}
}

struct S {
static func bar(fiz: [P], baz: [P]) {}
// expected-note@-1 {{'bar(fiz:baz:)' declared here}}
}

do {
let _ = M.foo(bar & // expected-error {{missing argument for parameter 'bar' in call}}
} // expected-error {{expected expression after operator}}

do {
let _ = S.bar(fiz & // expected-error {{missing argument for parameter 'fiz' in call}}
} // expected-error {{expected expression after operator}}