1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
// RUN: %target-typecheck-verify-swift
protocol Protocol1 {
func foo(arg1: Int, arg2: String) -> String // expected-note{{protocol requires function 'foo(arg1:arg2:)' with type '(Int, String) -> String'}}
func bar() throws -> String // expected-note{{protocol requires function 'bar()' with type '() throws -> String'}}
func generic<T>(t: T) // expected-note{{protocol requires function 'generic(t:)' with type '<T> (t: T) -> ()'}}
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'}}
var baz: Int { get } // expected-note{{protocol requires property 'baz' with type 'Int'}}
var baz2: Int { get set } // expected-note{{protocol requires property 'baz2' with type 'Int'}}
subscript(arg: Int) -> String { get } //expected-note{{rotocol requires subscript with type '(Int) -> String'}}
subscript(arg1: Int, arg2: Int) -> String { get set } //expected-note{{protocol requires subscript with type '(Int, Int) -> String'}}
}
class Adopter: Protocol1 { // expected-error{{type 'Adopter' does not conform to protocol 'Protocol1'}} expected-note {{add stubs for conformance}} {{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}}
}
protocol Protocol2 {
func foo(arg1: Int, arg2: String) -> String // expected-note{{protocol requires function 'foo(arg1:arg2:)' with type '(Int, String) -> String'}}
func bar() throws -> String // expected-note{{protocol requires function 'bar()' with type '() throws -> String'}}
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'}} {{none}}
var baz: Int { get } // expected-note{{protocol requires property 'baz' with type 'Int'}}
var baz2: Int { get set } // expected-note{{protocol requires property 'baz2' with type 'Int'}}
subscript(arg: Int) -> String { get } //expected-note{{rotocol requires subscript with type '(Int) -> String'}}
subscript(arg1: Int, arg2: Int) -> String { get set } //expected-note{{protocol requires subscript with type '(Int, Int) -> String'}}
}
class Adopter2 {}
extension Adopter2: Protocol2 { // expected-error {{ype 'Adopter2' does not conform to protocol 'Protocol2'}} expected-note {{add stubs for conformance}} {{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}}
}
protocol ProtocolWithAssocType {
associatedtype AssocType //expected-note{{protocol requires nested type 'AssocType'}}
}
struct Adopter3: ProtocolWithAssocType { //expected-error{{type 'Adopter3' does not conform to protocol 'ProtocolWithAssocType'}} expected-note {{add stubs for conformance}} {{41-41=\n typealias AssocType = <#type#>\n}}
}
protocol ProtocolWithAssocType2 {
associatedtype AssocType //expected-note{{protocol requires nested type 'AssocType'}}
}
struct Adopter4 {
}
extension Adopter4: ProtocolWithAssocType2 { //expected-error {{type 'Adopter4' does not conform to protocol 'ProtocolWithAssocType2'}} expected-note {{add stubs for conformance}} {{45-45=\n typealias AssocType = <#type#>\n}}
}
protocol ProtocolWithSelfRequirement {
func foo() -> Self // expected-note{{protocol requires function 'foo()' with type '() -> Adopter5'}}
func foo(lhs: Self, rhs: Self) -> Self //expected-note{{protocol requires function 'foo(lhs:rhs:)' with type '(Adopter5, Adopter5) -> Adopter5'}}
}
struct Adopter5: ProtocolWithSelfRequirement { //expected-error{{type 'Adopter5' does not conform to protocol 'ProtocolWithSelfRequirement'}} expected-note {{add stubs for conformance}} {{47-47=\n func foo() -> Adopter5 {\n <#code#>\n \}\n\n func foo(lhs: Adopter5, rhs: Adopter5) -> Adopter5 {\n <#code#>\n \}\n}}
}
protocol ProtocolWithSelfRequirement2 {
func foo() -> Self // expected-note{{protocol requires function 'foo()' with type '() -> Adopter6'}}
func foo(lhs: Self, rhs: Self) -> Self //expected-note{{protocol requires function 'foo(lhs:rhs:)' with type '(Adopter6, Adopter6) -> Adopter6'}}
}
struct Adopter6 {}
extension Adopter6: ProtocolWithSelfRequirement2 { //expected-error{{type 'Adopter6' does not conform to protocol 'ProtocolWithSelfRequirement2'}} expected-note {{add stubs for conformance}} {{51-51=\n func foo() -> Adopter6 {\n <#code#>\n \}\n\n func foo(lhs: Adopter6, rhs: Adopter6) -> Adopter6 {\n <#code#>\n \}\n}}
}
protocol ProtocolWithSelfRequirement3 {
func foo() -> Self // expected-note{{protocol requires function 'foo()' with type '() -> Self'}}
func foo(lhs: Self, rhs: Self) -> Self //expected-note{{protocol requires function 'foo(lhs:rhs:)' with type '(Adopter7, Adopter7) -> Self'}}
}
class Adopter7: ProtocolWithSelfRequirement3 { //expected-error{{type 'Adopter7' does not conform to protocol 'ProtocolWithSelfRequirement3'}} expected-note {{add stubs for conformance}} {{47-47=\n func foo() -> Self {\n <#code#>\n \}\n\n func foo(lhs: Adopter7, rhs: Adopter7) -> Self {\n <#code#>\n \}\n}}
}
public protocol ProtocolWithPublicAccess1 {
func foo() // expected-note{{protocol requires function 'foo()' with type '() -> ()'}}
}
public protocol ProtocolWithPublicAccess2 {
associatedtype AssocType //expected-note{{protocol requires nested type 'AssocType'}}
}
class Adopter8: ProtocolWithPublicAccess1, ProtocolWithPublicAccess2 {
// expected-error@-1{{type 'Adopter8' does not conform to protocol 'ProtocolWithPublicAccess1'}} expected-note@-1 {{add stubs for conformance}} {{71-71=\n func foo() {\n <#code#>\n \}\n\n typealias AssocType = <#type#>\n}}
// expected-error@-2{{type 'Adopter8' does not conform to protocol 'ProtocolWithPublicAccess2'}}
}
public protocol ProtocolWithPublicAccess3 {
func foo() // expected-note{{protocol requires function 'foo()' with type '() -> ()'}}
}
public protocol ProtocolWithPublicAccess4 {
associatedtype AssocType //expected-note{{protocol requires nested type 'AssocType'}}
}
public class Adopter9: ProtocolWithPublicAccess3, ProtocolWithPublicAccess4 {
// expected-error@-1{{type 'Adopter9' does not conform to protocol 'ProtocolWithPublicAccess3'}} expected-note@-1 {{add stubs for conformance}} {{78-78=\n public func foo() {\n <#code#>\n \}\n\n public typealias AssocType = <#type#>\n}}
// expected-error@-2{{type 'Adopter9' does not conform to protocol 'ProtocolWithPublicAccess4'}}
}
private protocol ProtocolWithPrivateAccess1 {
func foo() // expected-note{{protocol requires function 'foo()' with type '() -> ()'}}
}
private protocol ProtocolWithPrivateAccess2 {
associatedtype AssocType //expected-note{{protocol requires nested type 'AssocType'}}
}
class Adopter10: ProtocolWithPrivateAccess1, ProtocolWithPrivateAccess2 {
// expected-error@-1{{type 'Adopter10' does not conform to protocol 'ProtocolWithPrivateAccess1'}} expected-note@-1 {{add stubs for conformance}} {{74-74=\n func foo() {\n <#code#>\n \}\n\n typealias AssocType = <#type#>\n}}
// expected-error@-2{{type 'Adopter10' does not conform to protocol 'ProtocolWithPrivateAccess2'}}
}
private protocol ProtocolWithPrivateAccess3 {
func foo() // expected-note{{protocol requires function 'foo()' with type '() -> ()'}}
}
private protocol ProtocolWithPrivateAccess4 {
associatedtype AssocType //expected-note{{protocol requires nested type 'AssocType'}}
}
public class Adopter11: ProtocolWithPrivateAccess3, ProtocolWithPrivateAccess4 {
// expected-error@-1{{type 'Adopter11' does not conform to protocol 'ProtocolWithPrivateAccess3'}} expected-note@-1 {{add stubs for conformance}} {{81-81=\n func foo() {\n <#code#>\n \}\n\n typealias AssocType = <#type#>\n}}
// expected-error@-2{{type 'Adopter11' does not conform to protocol 'ProtocolWithPrivateAccess4'}}
}
protocol ProtocolRequiresInit1 {
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'}}
}
final class Adopter12 : ProtocolRequiresInit1 {} //expected-error {{type 'Adopter12' does not conform to protocol 'ProtocolRequiresInit1'}} expected-note {{add stubs for conformance}} {{48-48=\n init(arg: Int) {\n <#code#>\n \}\n}}
protocol ProtocolRequiresInit2 {
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'}}
}
final class Adopter13 {}
extension Adopter13 : ProtocolRequiresInit2 {} //expected-error {{type 'Adopter13' does not conform to protocol 'ProtocolRequiresInit2'}} expected-note {{add stubs for conformance}} {{46-46=\n convenience init(arg: Int) {\n <#code#>\n \}\n}}
protocol ProtocolRequiresInit3 {
init(arg: Int) // expected-note{{protocol requires initializer 'init(arg:)' with type '(arg: Int)'}}
}
struct Adopter14 {}
extension Adopter14 : ProtocolRequiresInit3 {} //expected-error {{type 'Adopter14' does not conform to protocol 'ProtocolRequiresInit3'}} expected-note {{add stubs for conformance}} {{46-46=\n init(arg: Int) {\n <#code#>\n \}\n}}
protocol ProtocolChain1 {
func foo1() // expected-note {{protocol requires function 'foo1()' with type '() -> ()'}}
func foo2() // expected-note {{protocol requires function 'foo2()' with type '() -> ()'}}
func foo3() // expected-note {{protocol requires function 'foo3()' with type '() -> ()'}}
var foo4 : Int {get set } // expected-note {{protocol requires property 'foo4' with type 'Int'}}
}
protocol ProtocolChain2 : ProtocolChain1 {
func bar1() // expected-note {{protocol requires function 'bar1()' with type '() -> ()'}}
func bar2() // expected-note {{protocol requires function 'bar2()' with type '() -> ()'}}
func bar3() // expected-note {{protocol requires function 'bar3()' with type '() -> ()'}}
var bar4 : Int {get set } // expected-note {{protocol requires property 'bar4' with type 'Int'}}
}
class Adopter15 : ProtocolChain2 {} //expected-error {{type 'Adopter15' does not conform to protocol 'ProtocolChain2'}} expected-error {{type 'Adopter15' does not conform to protocol 'ProtocolChain1'}} expected-note {{add stubs for conformance}} {{35-35=\n func bar1() {\n <#code#>\n \}\n\n func bar2() {\n <#code#>\n \}\n\n func bar3() {\n <#code#>\n \}\n\n var bar4: Int\n\n func foo1() {\n <#code#>\n \}\n\n func foo2() {\n <#code#>\n \}\n\n func foo3() {\n <#code#>\n \}\n\n var foo4: Int\n}}
protocol ProtocolParallel1 {
associatedtype Foo1 // expected-note {{protocol requires nested type 'Foo1'}}
associatedtype Foo2 // expected-note {{protocol requires nested type 'Foo2'}}
associatedtype Foo3 // expected-note {{protocol requires nested type 'Foo3'}}
func Foo4() // expected-note {{protocol requires function 'Foo4()' with type '() -> ()'}}
}
protocol ProtocolParallel2 {
associatedtype Bar1 // expected-note {{protocol requires nested type 'Bar1'}}
associatedtype Bar2 // expected-note {{protocol requires nested type 'Bar2'}}
associatedtype Bar3 // expected-note {{protocol requires nested type 'Bar3'}}
func Bar4() // expected-note {{protocol requires function 'Bar4()' with type '() -> ()'}}
}
class Adopter16 : ProtocolParallel1, ProtocolParallel2 {} // expected-error {{type 'Adopter16' does not conform to protocol 'ProtocolParallel1'}} expected-error {{type 'Adopter16' does not conform to protocol 'ProtocolParallel2'}} expected-note {{add stubs for conformance}} {{57-57=\n typealias Foo1 = <#type#>\n\n typealias Foo2 = <#type#>\n\n typealias Foo3 = <#type#>\n\n func Foo4() {\n <#code#>\n \}\n\n typealias Bar1 = <#type#>\n\n typealias Bar2 = <#type#>\n\n typealias Bar3 = <#type#>\n\n func Bar4() {\n <#code#>\n \}\n}}
protocol ProtocolParallel3 {
func foo1() // expected-note{{protocol requires function 'foo1()' with type '() -> ()'}}
func foo2() // expected-note{{protocol requires function 'foo2()' with type '() -> ()'}}
}
protocol ProtocolParallel4 {
func bar1()
func bar2()
}
class Adopter17: ProtocolParallel3, ProtocolParallel4 { // expected-error {{type 'Adopter17' does not conform to protocol 'ProtocolParallel3'}} expected-note {{add stubs for conformance}} {{56-56=\n func foo1() {\n <#code#>\n \}\n\n func foo2() {\n <#code#>\n \}\n}}
func bar1() {}
func bar2() {}
}
protocol ProtocolHasSubscriptFunction {
func `subscript`() // expected-note{{protocol requires function 'subscript()' with type '() -> ()'}}
}
class ProtocolHasSubscriptFunctionAdopter: ProtocolHasSubscriptFunction { // expected-error{{type 'ProtocolHasSubscriptFunctionAdopter' does not conform to protocol 'ProtocolHasSubscriptFunction'}} expected-note {{add stubs for conformance}} {{74-74=\n func `subscript`() {\n <#code#>\n \}\n}}
}
protocol ProtocolHasConsumingRequirement {
__consuming func foo() // expected-note {{protocol requires function 'foo()' with type '() -> ()'}}
}
struct ProtocolHasConsumingRequirementAdopter: ProtocolHasConsumingRequirement { // expected-error {{type 'ProtocolHasConsumingRequirementAdopter' does not conform to protocol 'ProtocolHasConsumingRequirement'}} expected-note {{add stubs for conformance}} {{81-81=\n func foo() {\n <#code#>\n \}\n}}
}
|