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
|
// RUN: %target-typecheck-verify-swift
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | %FileCheck %s
protocol P1 {
associatedtype T
}
protocol P2 {
associatedtype T : P1
}
struct S1<A, B, C> : P2
where A : P1, C : P2, B == A.T.T, C.T == A.T {
typealias T = C.T
}
struct S2<D : P1> : P2 {
typealias T = D
}
// Make sure that we can resolve the nested type A.T
// in the same-type requirement 'A.T == B.T'.
//
// A is concrete, and S1<C, E, S2<D>>.T resolves to
// S2<D>.T, which is D. The typealias S1.T has a
// structural type 'C.T'; since C is concrete, we
// have to handle the case of an unresolved member
// type with a concrete base.
struct UnresolvedWithConcreteBase<A, B> {
// CHECK-LABEL: Generic signature: <A, B, C, D, E where A == S1<C, E, S2<D>>, B : P2, C : P1, D == B.[P2]T, E == D.[P1]T, B.[P2]T == C.[P1]T>
init<C, D, E>(_: C)
where A == S1<C, E, S2<D>>,
B : P2,
A.T == B.T,
C : P1,
D == C.T,
E == D.T { }
}
// Make sure that we drop the conformance requirement
// 'A : P2' and rebuild the generic signature with the
// correct same-type requirements.
struct OriginalExampleWithRedundancy<A, B> where A : P2, B : P2, A.T == B.T {
// CHECK-LABEL: Generic signature: <A, B, C, D, E where A == S1<C, E, S2<D>>, B : P2, C : P1, D == B.[P2]T, E == D.[P1]T, B.[P2]T == C.[P1]T>
init<C, D, E>(_: C)
where C : P1,
D : P1,
C.T : P1,
A == S1<C, C.T.T, S2<C.T>>,
C.T == D,
E == D.T { }
}
struct OriginalExampleWithoutRedundancy<A, B> where A : P2, B : P2, A.T == B.T {
// CHECK-LABEL: Generic signature: <A, B, C, D, E where A == S1<C, E, S2<D>>, B : P2, C : P1, D == B.[P2]T, E == D.[P1]T, B.[P2]T == C.[P1]T>
init<C, D, E>(_: C)
where C : P1,
A == S1<C, C.T.T, S2<C.T>>,
C.T == D,
E == D.T { }
}
// Same as above but without unnecessary generic parameters.
struct WithoutBogusGenericParametersWithRedundancy<A, B> where A : P2, B : P2, A.T == B.T {
// CHECK-LABEL: Generic signature: <A, B, C where A == S1<C, B.[P2]T.[P1]T, S2<B.[P2]T>>, B : P2, C : P1, B.[P2]T == C.[P1]T>
init<C>(_: C)
where C : P1,
C.T : P1,
A == S1<C, C.T.T, S2<C.T>> {}
}
struct WithoutBogusGenericParametersWithoutRedundancy<A, B> where A : P2, B : P2, A.T == B.T {
// CHECK-LABEL: Generic signature: <A, B, C where A == S1<C, B.[P2]T.[P1]T, S2<B.[P2]T>>, B : P2, C : P1, B.[P2]T == C.[P1]T>
init<C>(_: C)
where C : P1,
A == S1<C, C.T.T, S2<C.T>> {}
}
|