// RUN: %target-typecheck-verify-swift protocol he where A : B { // expected-error {{cannot find type 'A' in scope}} // expected-error@-1 {{cannot find type 'B' in scope}} associatedtype vav where A : B // expected-error{{cannot find type 'A' in scope}} // expected-error@-1 {{cannot find type 'B' in scope}} } struct Lunch { struct Dinner { var leftovers: T var transformation: (T) -> U } } class Deli { // expected-note {{'Spices' declared as parameter to type 'Deli'}} // expected-note@-1 {{arguments to generic parameter 'Spices' ('Pepper' and 'ChiliFlakes') are expected to be equal}} class Pepperoni {} struct Sausage {} } struct Pizzas { // expected-note {{arguments to generic parameter 'Spices' ('ChiliFlakes' and 'Pepper') are expected to be equal}} class NewYork { } class DeepDish { } } class HotDog { } struct Pepper {} struct ChiliFlakes {} func eatDinnerConcrete(d: Pizzas.NewYork, t: Deli.Pepperoni) { } func eatDinnerConcrete(d: Pizzas.DeepDish, t: Deli.Pepperoni) { } func badDiagnostic1() { _ = Lunch.NewYork>.Dinner( leftovers: Pizzas.NewYork(), // expected-error {{cannot convert parent type 'Pizzas' to expected type 'Pizzas'}} transformation: { _ in HotDog() }) } func badDiagnostic2() { let firstCourse = Pizzas.NewYork() var dinner = Lunch.NewYork>.Dinner( leftovers: firstCourse, transformation: { _ in HotDog() }) let topping = Deli.Pepperoni() eatDinnerConcrete(d: firstCourse, t: topping) // expected-error@-1 {{cannot convert parent type 'Deli' to expected type 'Deli'}} } // Real error is that we cannot infer the generic parameter from context func takesAny(_ a: Any) {} func badDiagnostic3() { takesAny(Deli.self) // expected-error {{generic parameter 'Spices' could not be inferred}} // expected-note@-1 {{explicitly specify the generic arguments to fix this issue}} {{16-16=}} } // Crash with missing nested type inside concrete type class OuterGeneric { class InnerGeneric where U:OuterGeneric { // expected-error@-1 {{'NoSuchType' is not a member type of type 'T'}} func method() { _ = method } } } // Crash with missing types in requirements. protocol P1 { associatedtype A where A == ThisTypeDoesNotExist // expected-error@-1{{cannot find type 'ThisTypeDoesNotExist' in scope}} associatedtype B where ThisTypeDoesNotExist == B // expected-error@-1{{cannot find type 'ThisTypeDoesNotExist' in scope}} associatedtype C where ThisTypeDoesNotExist == ThisTypeDoesNotExist // expected-error@-1 2{{cannot find type 'ThisTypeDoesNotExist' in scope}} } // Diagnostic referred to the wrong type - protocol E { associatedtype XYZ } class P { func q(b:A) where A:E, N : A.XYZ { return } // expected-error@-1 {{type 'N' constrained to non-protocol, non-class type 'A.XYZ'}} } // https://github.com/apple/swift/issues/48151 protocol Foo { associatedtype Bar where Bar.Nonsense == Int // expected-error{{'Nonsense' is not a member type of type 'Self.Bar'}} } protocol Wibble : Foo where Bar.EvenMoreNonsense == Int { } // expected-error{{'EvenMoreNonsense' is not a member type of type 'Self.Bar'}} // rdar://45271500 - failure to emit a diagnostic enum Cat {} protocol Tail { associatedtype T } struct Dog where C.T == B {} func foo() -> Dog> {} // expected-error@-1 {{type 'Cat' does not conform to protocol 'Tail'}} // Tests for generic argument mismatch diagnosis struct X : Hashable { class Foo {} class Bar {} } // expected-note@-4 3 {{arguments to generic parameter 'A' ('Int' and 'Bool') are expected to be equal}} // expected-note@-5 2 {{arguments to generic parameter 'A' ('Bool' and 'Int') are expected to be equal}} // expected-note@-6 4 {{arguments to generic parameter 'A' ('Int' and 'Bool') are expected to be equal}} struct Y{} // expected-note {{arguments to generic parameter 'A' ('Int' and 'Bool') are expected to be equal}} // expected-note@-1 {{arguments to generic parameter 'C' ('Int' and 'Float') are expected to be equal}} struct YieldValue { var property: X { _read { yield X() // expected-error {{cannot convert value of type 'X' to expected yield type 'X'}} } } } func multipleArguments(y: Y) { let _: Y = y // expected-error {{cannot assign value of type 'Y' to type 'Y'}} } func errorMessageVariants(x: X, x2: X = X()) -> X { // expected-error@-1 {{default argument value of type 'X' cannot be converted to type 'X'}} let _: X = x // expected-error {{cannot assign value of type 'X' to type 'X'}} errorMessageVariants(x: x2, x2: x2) // expected-error {{cannot convert value of type 'X' to expected argument type 'X'}} let _: X = { return x }() // expected-error {{cannot convert value of type 'X' to closure result type 'X'}} let _: [X] = [x] // expected-error {{cannot convert value of type 'X' to expected element type 'X'}} let _ = x as X // expected-error {{cannot convert value of type 'X' to type 'X' in coercion}} let _: X.Foo = X.Foo() // expected-error {{cannot convert parent type 'X' to expected type 'X'}} return x // expected-error {{cannot convert return expression of type 'X' to return type 'X'}} }