Skip to content

Commit e4647bf

Browse files
committed
Sema: More tests for subclass existentials
1 parent b5ae8c4 commit e4647bf

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/type/subclass_composition.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,32 @@ protocol P1 {
77
class Base<T> : P1 {
88
typealias DependentClass = T
99

10+
required init(classInit: ()) {}
11+
1012
func classSelfReturn() -> Self {}
1113
}
1214

1315
protocol P2 {
1416
typealias FullyConcrete = Int
1517
typealias DependentProtocol = Self
1618

19+
init(protocolInit: ())
20+
1721
func protocolSelfReturn() -> Self
1822
}
1923

2024
typealias BaseAndP2<T> = Base<T> & P2
2125
typealias BaseIntAndP2 = BaseAndP2<Int>
2226

2327
class Derived : Base<Int>, P2 {
28+
required init(protocolInit: ()) {
29+
super.init(classInit: ())
30+
}
31+
32+
required init(classInit: ()) {
33+
super.init(classInit: ())
34+
}
35+
2436
func protocolSelfReturn() -> Self {}
2537
}
2638

@@ -147,6 +159,14 @@ func conformsToBaseIntAndP2WithWhereClause<T>(_: T) where T : Base<Int> & P2 {}
147159
// expected-note@-1 2 {{in call to function 'conformsToBaseIntAndP2WithWhereClause'}}
148160

149161
class FakeDerived : Base<String>, P2 {
162+
required init(classInit: ()) {
163+
super.init(classInit: ())
164+
}
165+
166+
required init(protocolInit: ()) {
167+
super.init(classInit: ())
168+
}
169+
150170
func protocolSelfReturn() -> Self { return self }
151171
}
152172

@@ -177,6 +197,16 @@ func metatypeSubtyping(
177197
let _: P2.Type = derivedAndAnyObject
178198
let _: (P2 & AnyObject).Type = derived
179199
let _: (P2 & AnyObject).Type = derivedAndAnyObject
200+
201+
// Initializers
202+
let _: Base<Int> & P2 = baseIntAndP2.init(classInit: ())
203+
let _: Base<Int> & P2 = baseIntAndP2.init(protocolInit: ())
204+
let _: Base<Int> & P2 & AnyObject = baseIntAndP2AndAnyObject.init(classInit: ())
205+
let _: Base<Int> & P2 & AnyObject = baseIntAndP2AndAnyObject.init(protocolInit: ())
206+
let _: Derived = derived.init(classInit: ())
207+
let _: Derived = derived.init(protocolInit: ())
208+
let _: Derived & AnyObject = derivedAndAnyObject.init(classInit: ())
209+
let _: Derived & AnyObject = derivedAndAnyObject.init(protocolInit: ())
180210
}
181211

182212
// There's a code path in CSApply that's hard to hit.
@@ -270,13 +300,30 @@ class ClassConformsToClassProtocolGood2 : Derived, ProtoRefinesClass {}
270300

271301
// Subclass existentials inside inheritance clauses
272302
class CompositionInClassInheritanceClauseAlias : BaseIntAndP2 {
303+
required init(classInit: ()) {
304+
super.init(classInit: ()) // FIXME: expected-error {{}}
305+
}
306+
307+
required init(protocolInit: ()) {
308+
super.init(classInit: ()) // FIXME: expected-error {{}}
309+
}
310+
273311
func protocolSelfReturn() -> Self { return self }
274312
func asBase() -> Base<Int> { return self }
275313
// FIXME expected-error@-1 {{}}
276314
}
277315

278316
class CompositionInClassInheritanceClauseDirect : Base<Int> & P2 {
279317
// expected-error@-1 {{protocol-constrained type is neither allowed nor needed here}}
318+
319+
required init(classInit: ()) {
320+
super.init(classInit: ())
321+
}
322+
323+
required init(protocolInit: ()) {
324+
super.init(classInit: ())
325+
}
326+
280327
func protocolSelfReturn() -> Self { return self }
281328
func asBase() -> Base<Int> { return self }
282329
}

0 commit comments

Comments
 (0)