Skip to content

Commit 14d3687

Browse files
committed
[SILGen] Test vtable thunk emission for overrides with contextual where clauses
1 parent d688710 commit 14d3687

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

test/SILGen/vtable_thunks_reabstraction.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,32 @@ class MoreGenericSub2<TT, T> : GenericBase<T> {
557557
// CHECK-NEXT: #GenericBase.init!allocator.1: <T><U> (GenericBase<T>.Type) -> (T, U) -> GenericBase<T> : @$s27vtable_thunks_reabstraction15MoreGenericSub2C1t1uACyxq_Gq__qd__tclufC [override]
558558
// CHECK-NEXT: #MoreGenericSub2.deinit!deallocator.1: @$s27vtable_thunks_reabstraction15MoreGenericSub2CfD // MoreGenericSub2.__deallocating_deinit
559559
// CHECK-NEXT: }
560+
561+
protocol SE_0267_P1 {}
562+
563+
class SE_0267_Base1<T> {
564+
func foo() where T: SE_0267_P1 {}
565+
}
566+
class SE_0267_Derived1<T>: SE_0267_Base1<T> {
567+
override func foo() {}
568+
}
569+
570+
// CHECK-LABEL: sil_vtable SE_0267_Derived1 {
571+
// CHECK-NEXT: #SE_0267_Base1.foo: <T where T : SE_0267_P1> (SE_0267_Base1<T>) -> () -> () : @$s27vtable_thunks_reabstraction16SE_0267_Derived1C3fooyyFAA0D11_0267_Base1CADyyAA0D8_0267_P1RzlFTV [override]
572+
// CHECK-NEXT: #SE_0267_Base1.init
573+
// CHECK-NEXT: #SE_0267_Derived1.foo: <T> (SE_0267_Derived1<T>) -> () -> () : @$s27vtable_thunks_reabstraction16SE_0267_Derived1C3fooyyF
574+
// CHECK-NEXT: #SE_0267_Derived1.deinit
575+
// CHECK-NEXT: }
576+
577+
class SE_0267_Base2<T> {
578+
func foo() -> T where T: FixedWidthInteger { fatalError() }
579+
}
580+
class SE_0267_Derived2: SE_0267_Base2<Int> {
581+
override func foo() -> Int { return .zero }
582+
}
583+
584+
// CHECK-LABEL: sil_vtable SE_0267_Derived2 {
585+
// CHECK-NEXT: #SE_0267_Base2.foo: <T where T : FixedWidthInteger> (SE_0267_Base2<T>) -> () -> T : @$s27vtable_thunks_reabstraction16SE_0267_Derived2C3fooSiyFAA0D11_0267_Base2CADxys17FixedWidthIntegerRzlFTV [override]
586+
// CHECK-NEXT: #SE_0267_Base2.init
587+
// CHECK-NEXT: #SE_0267_Derived2.deinit
588+
// CHECK-NEXT: }

test/attr/attr_override.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ class SR_4206_DerivedGeneric_6<T>: SR_4206_BaseConcrete_6 {
579579
override func foo<T: SR_4206_Protocol_1>(arg: T) {} // expected-error {{overridden method 'foo' has generic signature <T, T where T : SR_4206_Protocol_1> which is incompatible with base method's generic signature <T where T : SR_4206_Protocol_2>; expected generic signature to be <T, T where T : SR_4206_Protocol_2>}}
580580
}
581581

582-
// Where clauses on contextually generic declarations
582+
// Contextual where clauses on non-generic members
583583

584584
class SR_4206_Base_7<T> {
585585
func foo1() where T: SR_4206_Protocol_1 {} // expected-note {{overridden declaration is here}}
@@ -598,6 +598,14 @@ class SR_4206_Base_8<T> {
598598
func foo() where T: SR_4206_Protocol_1 {}
599599
}
600600
class SR_4206_Derived_8<T: SR_4206_Protocol_2, U>: SR_4206_Base_8<T> {
601+
// Because the generic signature of foo() is the same either way,
602+
// it may seem confusing that placing an additional constraint on the
603+
// generic parameter declaration directly has a different effect on
604+
// overridability in contrast to placing the constraint on foo().
605+
// The former (unlike the latter) is accepted because the constraint
606+
// in question only affects the ability to initialize an instance of the
607+
// subclass — not the visibility of the override itself relative to an
608+
// existing instance.
601609
override func foo() where T: SR_4206_Protocol_1 {} // OK
602610
}
603611

0 commit comments

Comments
 (0)