Skip to content

Commit 7d0bdb1

Browse files
committed
Omit protocol match diagnosis for constructors with differing names.
1 parent c7ae3e6 commit 7d0bdb1

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,16 @@ static void addOptionalityFixIts(
19611961
/// \brief Diagnose a requirement match, describing what went wrong (or not).
19621962
static void
19631963
diagnoseMatch(ModuleDecl *module, NormalProtocolConformance *conformance,
1964-
ValueDecl *req, const RequirementMatch &match){
1964+
ValueDecl *req, const RequirementMatch &match) {
1965+
1966+
// If we are matching a constructor and the name doesn't match,
1967+
// it is likely this witness wasn't intended to be a match at all, so omit
1968+
// diagnosis.
1969+
if (req->getKind() == DeclKind::Constructor && match.Kind != MatchKind::RenamedMatch
1970+
&& !match.Witness->getAttrs().hasAttribute<ImplementsAttr>() &&
1971+
req->getFullName() != match.Witness->getFullName())
1972+
return;
1973+
19651974
// Form a string describing the associated type deductions.
19661975
// FIXME: Determine which associated types matter, and only print those.
19671976
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/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/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)