@@ -58,7 +58,7 @@ public protocol ProtoWithAssocConf: AnyObject {
5858}
5959
6060public class GenClass2 < T> : Q {
61- var t : T
61+ final var t : T
6262
6363 init ( t : T ) { self . t = t }
6464
@@ -67,13 +67,28 @@ public class GenClass2<T>: Q {
6767 }
6868}
6969
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+
7078final public class GenClass3 < V> : ProtoWithAssocConf {
7179 public func foo( ) -> GenClass2 < Int > {
7280 print ( " foo " )
7381 return GenClass2 ( t: 27 )
7482 }
7583}
7684
85+ final public class OtherClass : ProtoWithAssocConf {
86+ public func foo( ) -> GenClass2 < Int > {
87+ print ( " other-foo " )
88+ return DerivedFromGenClass2 ( )
89+ }
90+ }
91+
7792
7893public func createExWithAssocConf( ) -> any ProtoWithAssocConf {
7994 return GenClass3 < Int > ( )
@@ -84,6 +99,63 @@ public func callExWithAssocConf(_ p: any ProtoWithAssocConf) {
8499 x. bar ( )
85100}
86101
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+
87159@main
88160struct Main {
89161 static func main( ) {
@@ -98,6 +170,17 @@ struct Main {
98170 callExWithAssocConf ( createExWithAssocConf ( ) )
99171 // CHECK: foo
100172 // 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
101184 }
102185}
103186
0 commit comments