// RUN: %target-typecheck-verify-swift -disable-availability-checking protocol P {} func invalid() {} // expected-error {{value generic 'N' must have an explicit value type declared}} // expected-error@-1 {{generic parameter 'N' is not used in function signature}} func invalid(_: A) {} // expected-error {{value generic 'N' must have an explicit value type declared}} struct A { var int: Int { N // OK } var uint: UInt { N // expected-error {{cannot convert return expression of type 'Int' to return type 'UInt'}} } var goodUInt: UInt { UInt(N) // OK } var intSelf: Int { N.self // OK } var n: N { // expected-error {{using value generic 'N' here is not allowed}} fatalError() } var nType: N.Type { // expected-error {{using value generic 'N' here is not allowed}} fatalError() } var a: A { // OK fatalError() } } extension A where N: P {} // expected-error {{value generic type 'N' cannot conform to protocol 'P'}} extension A where N == Int {} // expected-error {{cannot constrain value parameter 'N' to be type 'Int'}} extension A where N == 123 { func thing() -> Int { N // OK (this used to crash the compiler in a concrete case 'where N == 123') } } func b(with a: A<123>) {} // OK func c(with a: A) {} // OK func d(with a: A) {} // expected-error {{cannot pass type 'T' as a value for generic value 'N'}} func e(with a: A) {} // expected-error {{cannot pass type 'Int' as a value for generic value 'N'}} struct Generic {} struct GenericWithIntParam {} extension Generic where T == 123 {} // expected-error {{cannot constrain type parameter 'T' to be integer '123'}} extension Generic where T == 123.Type {} // expected-error {{cannot constrain type parameter 'T' to be integer '123'}} // expected-error@-1 {{expected '{' in extension}} extension Generic where T == 123? {} // expected-error {{cannot constrain type parameter 'T' to be integer '123'}} // expected-error@-1 {{expected '{' in extension}} func f(_: Generic<123>) {} // expected-error {{integer unexpectedly used in a type position}} func g(_: Generic) {} // expected-error {{cannot use value type 'N' for generic argument 'T'}} func h(_: (Int, 123)) {} // expected-error {{expected type}} func i(_: () -> 123) {} // expected-error {{expected type}} func j(_: (A<123>) -> ()) {} // OK func k(_: some 123) {} // expected-error {{expected parameter type following ':'}} func l(_: GenericWithIntParam<123, Int>) {} // expected-error@-1 {{cannot pass type 'Int' as a value for generic value 'N'}} // expected-error@-2 {{cannot use value type '123' for generic argument 'T'}} func m(_: GenericWithIntParam) {} // OK typealias One = 1 // expected-error {{expected type in type alias declaration}} struct B {} // expected-error {{'UInt8' is not a supported value type for 'N'}} struct C {} extension C where N == 123 { // expected-note {{where 'N' = '0'}} // expected-note@-1 {{where 'N' = '0'}} // expected-note@-2 {{where 'N' = 'T'}} func nIs123() {} } extension C where M == 321 { // expected-note {{where 'M' = '0'}} // expected-note@-1 {{where 'M' = '0'}} // expected-note@-2 {{where 'M' = 'T'}} func mIs123() {} } extension C where N == M { // expected-note {{where 'N' = '123', 'M' = '0'}} // expected-note@-1 {{where 'N' = '0', 'M' = '321'}} func nAndMAreBothEqual() {} } func testC1(with c: C<0, 0>) { c.nIs123() // expected-error {{referencing instance method 'nIs123()' on 'C' requires the types '0' and '123' be equivalent}} c.mIs123() // expected-error {{referencing instance method 'mIs123()' on 'C' requires the types '0' and '321' be equivalent}} c.nAndMAreBothEqual() // OK } func testC2(with c: C<123, 0>) { c.nIs123() // OK c.mIs123() // expected-error {{referencing instance method 'mIs123()' on 'C' requires the types '0' and '321' be equivalent}} c.nAndMAreBothEqual() // expected-error {{referencing instance method 'nAndMAreBothEqual()' on 'C' requires the types '123' and '0' be equivalent}} } func testC3(with c: C<0, 321>) { c.nIs123() // expected-error {{referencing instance method 'nIs123()' on 'C' requires the types '0' and '123' be equivalent}} c.mIs123() // OK c.nAndMAreBothEqual() // expected-error {{referencing instance method 'nAndMAreBothEqual()' on 'C' requires the types '0' and '321' be equivalent}} } func testC4(with c: C) { c.nIs123() // expected-error {{referencing instance method 'nIs123()' on 'C' requires the types 'T' and '123' be equivalent}} c.mIs123() // expected-error {{referencing instance method 'mIs123()' on 'C' requires the types 'T' and '321' be equivalent}} c.nAndMAreBothEqual() // OK } struct D {} // expected-error {{non-protocol, non-class type 'Int' cannot be used within a protocol-constrained type}}