Skip to content

Commit 4f8e3f3

Browse files
authored
Merge pull request swiftlang#19879 from gregomni/8757
[Sema] Omit protocol match diagnosis for constructors with differing names.
2 parents d290f19 + 85baf3f commit 4f8e3f3

File tree

11 files changed

+23
-21
lines changed

11 files changed

+23
-21
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,17 @@ static void addOptionalityFixIts(
19691969
/// \brief Diagnose a requirement match, describing what went wrong (or not).
19701970
static void
19711971
diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
1972-
ValueDecl *req, const RequirementMatch &match){
1972+
ValueDecl *req, const RequirementMatch &match) {
1973+
1974+
// If the name doesn't match and that's not the only problem,
1975+
// it is likely this witness wasn't intended to be a match at all, so omit
1976+
// diagnosis.
1977+
if (match.Kind != MatchKind::RenamedMatch &&
1978+
!match.Witness->getAttrs().hasAttribute<ImplementsAttr>() &&
1979+
match.Witness->getFullName() &&
1980+
req->getFullName() != match.Witness->getFullName())
1981+
return;
1982+
19731983
// Form a string describing the associated type deductions.
19741984
// FIXME: Determine which associated types matter, and only print those.
19751985
llvm::SmallString<128> withAssocTypes;

test/ClangImporter/objc_parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func classAnyObject(_ obj: NSObject) {
270270
}
271271

272272
// Protocol conformances
273-
class Wobbler : NSWobbling { // expected-note{{candidate has non-matching type '()'}}
273+
class Wobbler : NSWobbling {
274274
@objc func wobble() { }
275275

276276
func returnMyself() -> Self { return self } // expected-error{{non-'@objc' method 'returnMyself()' does not satisfy requirement of '@objc' protocol 'NSWobbling'}}{{none}}
@@ -280,7 +280,7 @@ class Wobbler : NSWobbling { // expected-note{{candidate has non-matching type '
280280
extension Wobbler : NSMaybeInitWobble { // expected-error{{type 'Wobbler' does not conform to protocol 'NSMaybeInitWobble'}}
281281
}
282282

283-
@objc class Wobbler2 : NSObject, NSWobbling { // expected-note{{candidate has non-matching type '()'}}
283+
@objc class Wobbler2 : NSObject, NSWobbling {
284284
func wobble() { }
285285
func returnMyself() -> Self { return self }
286286
}

test/Compatibility/special_func_name.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ protocol P2 {
1818
}
1919

2020
struct S21 : P2 { // expected-error {{type 'S21' does not conform to protocol 'P2'}}
21-
// expected-note@-1 {{candidate has non-matching type '()'}}
2221
static func `init`(_: Int) {}
2322
}
2423

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/func/special_func_name.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ protocol P2 {
1818
}
1919

2020
struct S21 : P2 { // expected-error {{type 'S21' does not conform to protocol 'P2'}}
21-
// expected-note@-1 {{candidate has non-matching type '()'}}
2221
static func `init`(_: Int) {}
2322
}
2423

test/decl/protocol/conforms/failure.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct P6Conformer : P6 { // expected-error 2 {{does not conform}}
9797
// expected-error@+1{{type 'A' does not conform to protocol 'RawRepresentable'}}
9898
struct A: OptionSet {
9999
let rawValue = 0
100-
init() { } // expected-note 2{{candidate has non-matching type '()'}}
100+
init() { }
101101
}
102102

103103
// Type witness cannot have its own generic parameters

test/decl/protocol/conforms/fixit_stub.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ protocol Protocol1 {
1111
subscript(arg1: Int, arg2: Int) -> String { get set } //expected-note{{protocol requires subscript with type '(Int, Int) -> String'; do you want to add a stub?}} {{27-27=\n func foo(arg1: Int, arg2: String) -> String {\n <#code#>\n \}\n\n func bar() throws -> String {\n <#code#>\n \}\n\n func generic<T>(t: T) {\n <#code#>\n \}\n\n required init(arg: Int) {\n <#code#>\n \}\n\n var baz: Int\n\n var baz2: Int\n\n subscript(arg: Int) -> String {\n <#code#>\n \}\n\n subscript(arg1: Int, arg2: Int) -> String {\n get {\n <#code#>\n \}\n set {\n <#code#>\n \}\n \}\n}}
1212
}
1313

14-
class Adopter: Protocol1 { // expected-error{{type 'Adopter' does not conform to protocol 'Protocol1'}} expected-note{{candidate has non-matching type '()'}}
14+
class Adopter: Protocol1 { // expected-error{{type 'Adopter' does not conform to protocol 'Protocol1'}}
1515
}
1616

1717

@@ -26,7 +26,7 @@ protocol Protocol2 {
2626
subscript(arg1: Int, arg2: Int) -> String { get set } //expected-note{{protocol requires subscript with type '(Int, Int) -> String'; do you want to add a stub?}} {{32-32=\n func foo(arg1: Int, arg2: String) -> String {\n <#code#>\n \}\n\n func bar() throws -> String {\n <#code#>\n \}\n\n var baz: Int {\n <#code#>\n \}\n\n var baz2: Int {\n get {\n <#code#>\n \}\n set {\n <#code#>\n \}\n \}\n\n subscript(arg: Int) -> String {\n <#code#>\n \}\n\n subscript(arg1: Int, arg2: Int) -> String {\n get {\n <#code#>\n \}\n set {\n <#code#>\n \}\n \}\n}}
2727
}
2828

29-
class Adopter2 {} // expected-note{{candidate has non-matching type '()'}}
29+
class Adopter2 {}
3030

3131
extension Adopter2: Protocol2 { // expected-error{{ype 'Adopter2' does not conform to protocol 'Protocol2'}}
3232
}
@@ -131,19 +131,19 @@ public class Adopter11: ProtocolWithPrivateAccess3, ProtocolWithPrivateAccess4 {
131131
protocol ProtocolRequiresInit1 {
132132
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'; do you want to add a stub?}} {{48-48=\n init(arg: Int) {\n <#code#>\n \}\n}}
133133
}
134-
final class Adopter12 : ProtocolRequiresInit1 {} //expected-error {{type 'Adopter12' does not conform to protocol 'ProtocolRequiresInit1'}} // expected-note{{candidate}}
134+
final class Adopter12 : ProtocolRequiresInit1 {} //expected-error {{type 'Adopter12' does not conform to protocol 'ProtocolRequiresInit1'}}
135135

136136
protocol ProtocolRequiresInit2 {
137137
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'; do you want to add a stub?}} {{46-46=\n convenience init(arg: Int) {\n <#code#>\n \}\n}}
138138
}
139-
final class Adopter13 {} // expected-note{{candidate}}
139+
final class Adopter13 {}
140140
extension Adopter13 : ProtocolRequiresInit2 {} //expected-error {{type 'Adopter13' does not conform to protocol 'ProtocolRequiresInit2'}}
141141

142142
protocol ProtocolRequiresInit3 {
143143
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'; do you want to add a stub?}} {{46-46=\n init(arg: Int) {\n <#code#>\n \}\n}}
144144
}
145145

146-
struct Adopter14 {} // expected-note{{candidate}}
146+
struct Adopter14 {}
147147
extension Adopter14 : ProtocolRequiresInit3 {} //expected-error {{type 'Adopter14' does not conform to protocol 'ProtocolRequiresInit3'}}
148148

149149
protocol ProtocolChain1 {

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 {

test/decl/protocol/special/coding/enum_coding_key.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ enum Int8Key : Int8, CodingKey { // expected-error {{type 'Int8Key' does not con
4141

4242
// Structs conforming to CodingKey should not get implicit derived conformance.
4343
struct StructKey : CodingKey { // expected-error {{type 'StructKey' does not conform to protocol 'CodingKey'}}
44-
// expected-note@-1 {{candidate has non-matching type '()'}}
45-
// expected-note@-2 {{candidate has non-matching type '()'}}
4644
}
4745

4846
// Classes conforming to CodingKey should not get implict derived conformance.
4947
class ClassKey : CodingKey { //expected-error {{type 'ClassKey' does not conform to protocol 'CodingKey'}}
50-
// expected-note@-1 {{candidate has non-matching type '()'}}
51-
// expected-note@-2 {{candidate has non-matching type '()'}}
5248
}
5349

5450
// Types which are valid for CodingKey derived conformance should not get that

0 commit comments

Comments
 (0)