Skip to content

Commit 2e23ee5

Browse files
committed
Exclude non-matching name diagonses for all candidates.
1 parent 7d0bdb1 commit 2e23ee5

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,11 +1963,12 @@ static void
19631963
diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
19641964
ValueDecl *req, const RequirementMatch &match) {
19651965

1966-
// If we are matching a constructor and the name doesn't match,
1966+
// If the name doesn't match and that's not the only problem,
19671967
// it is likely this witness wasn't intended to be a match at all, so omit
19681968
// diagnosis.
1969-
if (req->getKind() == DeclKind::Constructor && match.Kind != MatchKind::RenamedMatch
1970-
&& !match.Witness->getAttrs().hasAttribute<ImplementsAttr>() &&
1969+
if (match.Kind != MatchKind::RenamedMatch &&
1970+
!match.Witness->getAttrs().hasAttribute<ImplementsAttr>() &&
1971+
match.Witness->getFullName() &&
19711972
req->getFullName() != match.Witness->getFullName())
19721973
return;
19731974

test/Constraints/generic_protocol_witness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TooTightConstraints : NeedsGenericMethods { // expected-error{{type 'TooTi
4242
func oneArgWithConstraint<U : Fungible>(x: U) {} // expected-note{{candidate has non-matching type '<U> (x: U) -> ()'}}
4343
func oneArgWithConstraints<U : Runcible & Fungible & Ansible>(x: U) {} // expected-note{{candidate has non-matching type '<U> (x: U) -> ()'}}
4444

45-
func twoArgsOneVar<U : Runcible>(x: U) {} // expected-note{{candidate has non-matching type '<U> (x: U) -> ()'}}
45+
func twoArgsOneVar<U : Runcible>(x: U) {}
4646
func twoArgsTwoVars<U>(x: U, y: U) {} // expected-note{{candidate has non-matching type '<U> (x: U, y: U) -> ()'}}
4747
}
4848
func (_ x: TooTightConstraints, y: Int) {} // expected-note {{candidate has non-matching type '(TooTightConstraints, Int) -> ()'}}

test/decl/protocol/protocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class NotPrintableC : CustomStringConvertible, Any {} // expected-error{{type 'N
7777
enum NotPrintableO : Any, CustomStringConvertible {} // expected-error{{type 'NotPrintableO' does not conform to protocol 'CustomStringConvertible'}}
7878

7979
struct NotFormattedPrintable : FormattedPrintable { // expected-error{{type 'NotFormattedPrintable' does not conform to protocol 'CustomStringConvertible'}}
80-
func print(format: TestFormat) {} // expected-note{{candidate has non-matching type '(TestFormat) -> ()'}}
80+
func print(format: TestFormat) {}
8181
}
8282

8383
// Protocol compositions in inheritance clauses

test/decl/protocol/req/func.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct X2x : P2 { // expected-error{{type 'X2x' does not conform to protocol 'P2
7474
// Mismatch in parameter types
7575
struct X2y : P2 { // expected-error{{type 'X2y' does not conform to protocol 'P2'}}
7676
typealias Assoc = X1a
77-
func f1(x: X1b) { } // expected-note{{candidate has non-matching type '(X1b) -> ()'}}
77+
func f1(x: X1b) { }
7878
}
7979

8080
// Ambiguous deduction
@@ -192,7 +192,7 @@ protocol P6 {
192192
}
193193
struct X6 : P6 { // expected-error{{type 'X6' does not conform to protocol 'P6'}}
194194
func foo(_ x: Missing) { } // expected-error{{use of undeclared type 'Missing'}}
195-
func bar() { } // expected-note{{candidate has non-matching type '() -> ()'}}
195+
func bar() { }
196196
}
197197

198198
protocol P6Ownership {

0 commit comments

Comments
 (0)