@@ -58,7 +58,7 @@ public protocol ProtoWithAssocConf: AnyObject {
58
58
}
59
59
60
60
public class GenClass2 < T> : Q {
61
- var t : T
61
+ final var t : T
62
62
63
63
init ( t : T ) { self . t = t }
64
64
@@ -67,13 +67,28 @@ public class GenClass2<T>: Q {
67
67
}
68
68
}
69
69
70
+ public class DerivedFromGenClass2 : GenClass2 < Int > {
71
+ init ( ) { super. init ( t: 42 ) }
72
+
73
+ public override func bar( ) {
74
+ print ( " derived-bar " )
75
+ }
76
+ }
77
+
70
78
final public class GenClass3 < V> : ProtoWithAssocConf {
71
79
public func foo( ) -> GenClass2 < Int > {
72
80
print ( " foo " )
73
81
return GenClass2 ( t: 27 )
74
82
}
75
83
}
76
84
85
+ final public class OtherClass : ProtoWithAssocConf {
86
+ public func foo( ) -> GenClass2 < Int > {
87
+ print ( " other-foo " )
88
+ return DerivedFromGenClass2 ( )
89
+ }
90
+ }
91
+
77
92
78
93
public func createExWithAssocConf( ) -> any ProtoWithAssocConf {
79
94
return GenClass3 < Int > ( )
@@ -84,6 +99,63 @@ public func callExWithAssocConf(_ p: any ProtoWithAssocConf) {
84
99
x. bar ( )
85
100
}
86
101
102
+ public class Base < T> : ClassBound {
103
+ public func foo( ) { print ( " Base.foo() " ) }
104
+ public func bar( ) { print ( " Base.bar() " ) }
105
+ }
106
+
107
+ public class Derived1 : Base < Int > {
108
+ public override func foo( ) { print ( " Derived1.foo() " ) }
109
+ public override func bar( ) { print ( " Derived1.bar() " ) }
110
+ }
111
+
112
+ public class Derived2 < T> : Base < T > {
113
+ public override func foo( ) { print ( " Derived2.foo() " ) }
114
+ public override func bar( ) { print ( " Derived2.bar() " ) }
115
+ }
116
+
117
+ public func takes_p1( _ p: P1 ) {
118
+ p. normal ( )
119
+ }
120
+
121
+ public protocol P1 : AnyObject {
122
+ func normal( )
123
+ }
124
+
125
+ public protocol P2 {
126
+ func foo( )
127
+ }
128
+
129
+ public class ConditionalConformanceBase < A> {
130
+ final var a : A
131
+
132
+ init ( a: A ) { self . a = a }
133
+ }
134
+
135
+ extension ConditionalConformanceBase : P1 where A: P2 {
136
+ public func normal( ) {
137
+ a. foo ( )
138
+ }
139
+ }
140
+
141
+ public class ConditionalConformanceDerived < T> : ConditionalConformanceBase < T > {
142
+ init ( t: T ) { super. init ( a: t) }
143
+ }
144
+
145
+
146
+ public func testConditionalConformance< T: P2 > ( t: T ) {
147
+ takes_p1 ( ConditionalConformanceDerived ( t: t) )
148
+ }
149
+
150
+
151
+ struct S : P2 {
152
+ var i : Int
153
+
154
+ func foo( ) {
155
+ print ( i)
156
+ }
157
+ }
158
+
87
159
@main
88
160
struct Main {
89
161
static func main( ) {
@@ -98,6 +170,17 @@ struct Main {
98
170
callExWithAssocConf ( createExWithAssocConf ( ) )
99
171
// CHECK: foo
100
172
// CHECK: bar
173
+ callExWithAssocConf ( OtherClass ( ) )
174
+ // CHECK: other-foo
175
+ // CHECK: derived-bar
176
+ test ( existential: Derived1 ( ) )
177
+ // CHECK: Derived1.foo()
178
+ // CHECK: Derived1.bar()
179
+ test ( existential: Derived2 < Bool > ( ) )
180
+ // CHECK: Derived2.foo()
181
+ // CHECK: Derived2.bar()
182
+ testConditionalConformance ( t: S ( i: 27 ) )
183
+ // CHECK: 27
101
184
}
102
185
}
103
186
0 commit comments