Skip to content

Commit 1c1aed7

Browse files
committed
Add some tests for @testable and subclassing.
Inspired by the previous commit. These are things we expect to keep working.
1 parent c6a7920 commit 1c1aed7

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

test/NameBinding/Inputs/has_accessibility.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ public protocol HasDefaultImplementation {}
3939
extension HasDefaultImplementation {
4040
internal func foo() {}
4141
}
42+
internal class InternalBase {}

test/NameBinding/accessibility.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,9 @@ public protocol Fooable {
167167
#if !ACCESS_DISABLED
168168
internal struct FooImpl: Fooable, HasDefaultImplementation {} // expected-error {{type 'FooImpl' does not conform to protocol 'Fooable'}}
169169
public struct PublicFooImpl: Fooable, HasDefaultImplementation {} // expected-error {{type 'PublicFooImpl' does not conform to protocol 'Fooable'}}
170-
#endif
171170
// TESTABLE-NOT: method 'foo()'
171+
172+
internal class TestableSub: InternalBase {} // expected-error {{undeclared type 'InternalBase'}}
173+
public class TestablePublicSub: InternalBase {} // expected-error {{undeclared type 'InternalBase'}}
174+
// TESTABLE-NOT: undeclared type 'InternalBase'
175+
#endif

test/SILGen/Inputs/TestableMultifileHelper.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ public protocol HasDefaultFoo {}
22
extension HasDefaultFoo {
33
internal func foo() {}
44
}
5+
6+
internal class Base {
7+
func foo() {}
8+
}

test/SILGen/testable-multifile-other.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ func test(internalFoo: FooImpl, publicFoo: PublicFooImpl) {
3030
// CHECK: [[IMPL_2:%.+]] = function_ref @_TFE23TestableMultifileHelperPS_13HasDefaultFoo3foofT_T_
3131
// CHECK: = apply [[IMPL_2]]<PublicFooImpl>({{%.+}}) : $@convention(method) <τ_0_0 where τ_0_0 : HasDefaultFoo> (@in_guaranteed τ_0_0) -> ()
3232
// CHECK: {{^}$}}
33+
34+
func test(internalSub: Sub, publicSub: PublicSub) {
35+
internalSub.foo()
36+
publicSub.foo()
37+
}
38+
39+
// CHECK-LABEL: sil hidden @_TF4main4testFT11internalSubCS_3Sub9publicSubCS_9PublicSub_T_
40+
// CHECK: = class_method %0 : $Sub, #Sub.foo!1
41+
// CHECK: = class_method %1 : $PublicSub, #PublicSub.foo!1
42+
// CHECK: {{^}$}}
43+

test/SILGen/testable-multifile.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ public struct PublicFooImpl: Fooable, HasDefaultFoo {}
2828
// CHECK: function_ref @_TFE23TestableMultifileHelperPS_13HasDefaultFoo3foofT_T_
2929
// CHECK: {{^}$}}
3030

31+
private class PrivateSub: Base {
32+
fileprivate override func foo() {}
33+
}
34+
class Sub: Base {
35+
internal override func foo() {}
36+
}
37+
public class PublicSub: Base {
38+
public override func foo() {}
39+
}
40+
41+
// CHECK-LABEL: sil_vtable PrivateSub {
42+
// CHECK-NEXT: #Base.foo!1: _TFC4mainP33_F1525133BD493492AD72BF10FBCB1C5210PrivateSub3foofT_T_
43+
// CHECK-NEXT: #Base.init!initializer.1: _TFC4mainP33_F1525133BD493492AD72BF10FBCB1C5210PrivateSubcfT_S0_
44+
// CHECK-NEXT: #PrivateSub.deinit!deallocator: _TFC4mainP33_F1525133BD493492AD72BF10FBCB1C5210PrivateSubD
45+
// CHECK-NEXT: }
46+
47+
// CHECK-LABEL: sil_vtable Sub {
48+
// CHECK-NEXT: #Base.foo!1: _TFC4main3Sub3foofT_T_
49+
// CHECK-NEXT: #Base.init!initializer.1: _TFC4main3SubcfT_S0_
50+
// CHECK-NEXT: #Sub.deinit!deallocator: _TFC4main3SubD
51+
// CHECK-NEXT: }
52+
53+
// CHECK-LABEL: sil_vtable PublicSub {
54+
// CHECK-NEXT: #Base.foo!1: _TFC4main9PublicSub3foofT_T_
55+
// CHECK-NEXT: #Base.init!initializer.1: _TFC4main9PublicSubcfT_S0_
56+
// CHECK-NEXT: #PublicSub.deinit!deallocator: _TFC4main9PublicSubD
57+
// CHECK-NEXT: }
58+
59+
60+
3161
// CHECK-LABEL: sil_witness_table FooImpl: Fooable module main {
3262
// CHECK-NEXT: method #Fooable.foo!1: @_TTWV4main7FooImplS_7FooableS_FS1_3foofT_T_
3363
// CHECK-NEXT: }

0 commit comments

Comments
 (0)