// RUN: %target-run-simple-swift(-target %target-swift-5.9-abi-triple) // REQUIRES: executable_test // UNSUPPORTED: use_os_stdlib // UNSUPPORTED: back_deployment_runtime import StdlibUnittest var conformances = TestSuite("VariadicGenericConformances") protocol P { static func foobar() -> [String] } struct G {} extension G: P where repeat each T: P { static func foobar() -> [String] { var result: [String] = [] repeat result += (each T).foobar() return result } } extension Int: P { static func foobar() -> [String] { return ["Int"] } } extension String: P { static func foobar() -> [String] { return ["String"] } } func callFoobar(_: T) -> [String] { return T.foobar() } conformances.test("conditional") { expectEqual([], callFoobar(G< >())) expectEqual(["Int"], callFoobar(G())) expectEqual(["Int", "String"], callFoobar(G())) } func cast(_ value: T, to: U.Type) -> Bool { return value is U } conformances.test("cast") { expectEqual(true, cast(G< >(), to: (any P).self)) expectEqual(true, cast(G(), to: (any P).self)) expectEqual(true, cast(G(), to: (any P).self)) expectEqual(false, cast(G(), to: (any P).self)) expectEqual(false, cast(G(), to: (any P).self)) expectEqual(false, cast(G(), to: (any P).self)) } struct Outer { struct Inner {} } extension Outer.Inner: P where repeat (repeat (each U, each V)): Any { static func foobar() -> [String] { return ["hello"] } } conformances.test("shape") { expectEqual(true, cast(Outer< >.Inner< >(), to: (any P).self)) expectEqual(true, cast(Outer.Inner(), to: (any P).self)) expectEqual(true, cast(Outer.Inner(), to: (any P).self)) expectEqual(false, cast(Outer.Inner< >(), to: (any P).self)) expectEqual(false, cast(Outer.Inner(), to: (any P).self)) } runAllTests()