Skip to content

Commit cb8ebb3

Browse files
authored
Merge pull request #12001 from slavapestov/final-override-of-dynamic-method-4.0
Sema: Fix assertion failure when overriding a dynamic method with a final method [4.0]
2 parents 4fe104e + f2f9e2e commit cb8ebb3

File tree

3 files changed

+99
-66
lines changed

3 files changed

+99
-66
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6235,6 +6235,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
62356235
}
62366236

62376237
void visitDynamicAttr(DynamicAttr *attr) {
6238+
// Final overrides are not dynamic.
6239+
if (Override->isFinal())
6240+
return;
6241+
62386242
makeDynamic(TC.Context, Override);
62396243
}
62406244

test/SILGen/vtables.swift

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
// RUN: %target-swift-frontend -sdk %S/Inputs -emit-silgen -I %S/Inputs -enable-source-import %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
2-
3-
// FIXME: rdar://problem/19648117 Needs splitting objc parts out
4-
// XFAIL: linux
5-
6-
import gizmo
7-
8-
// TODO: Generic base classes
1+
// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
92

103
// Test for compilation order independence
114
class C : B {
@@ -73,64 +66,6 @@ class B : A {
7366
// CHECK: #B.zang!1: {{.*}} : _T07vtables1BC4zang{{[_0-9a-zA-Z]*}}F
7467
// CHECK: }
7568

76-
// Test ObjC base class
77-
78-
class Hoozit : Gizmo {
79-
// Overrides Gizmo.frob
80-
override func frob() {}
81-
// Overrides Gizmo.funge
82-
override func funge() {}
83-
84-
func anse() {}
85-
func incorrige() {}
86-
}
87-
88-
// Entries only exist for native Swift methods
89-
90-
// CHECK: sil_vtable Hoozit {
91-
// CHECK-NEXT: #Hoozit.anse!1: {{.*}} : _T07vtables6HoozitC4anse{{[_0-9a-zA-Z]*}}F
92-
// CHECK-NEXT: #Hoozit.incorrige!1: {{.*}} : _T07vtables6HoozitC9incorrige{{[_0-9a-zA-Z]*}}F
93-
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> () -> Hoozit! : _T07vtables6HoozitCSQyACGycfc
94-
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> (Int) -> Hoozit! : _T07vtables6HoozitCSQyACGSi7bellsOn_tcfc
95-
// CHECK-NEXT: #Hoozit.deinit!deallocator: _T07vtables6HoozitCfD
96-
// CHECK-NEXT: }
97-
98-
class Wotsit : Hoozit {
99-
override func funge() {}
100-
override func incorrige() {}
101-
}
102-
103-
// CHECK: sil_vtable Wotsit {
104-
// CHECK-NEXT: #Hoozit.anse!1: {{.*}} : _T07vtables6HoozitC4anse{{[_0-9a-zA-Z]*}}F
105-
// CHECK-NEXT: #Hoozit.incorrige!1: {{.*}} : _T07vtables6WotsitC9incorrige{{[_0-9a-zA-Z]*}}F
106-
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> () -> Hoozit! : _T07vtables6WotsitCSQyACGycfc
107-
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> (Int) -> Hoozit! : _T07vtables6WotsitCSQyACGSi7bellsOn_tcfc
108-
// CHECK-NEXT: #Wotsit.deinit!deallocator: _T07vtables6WotsitCfD
109-
// CHECK-NEXT: }
110-
111-
// <rdar://problem/15282548>
112-
// CHECK: sil_vtable Base {
113-
// CHECK: #Base.init!initializer.1: {{.*}} : _T07vtables4BaseC{{[_0-9a-zA-Z]*}}fc
114-
// CHECK: }
115-
// CHECK: sil_vtable Derived {
116-
// CHECK: #Base.init!initializer.1: {{.*}} : _T07vtables7DerivedC{{[_0-9a-zA-Z]*}}fc
117-
// CHECK: }
118-
@objc class Base {}
119-
120-
extension Base {
121-
// note: does not have a vtable slot, because it is from an extension
122-
func identify() -> Int {
123-
return 0
124-
}
125-
}
126-
127-
class Derived : Base {
128-
override func identify() -> Int {
129-
return 1
130-
}
131-
}
132-
133-
13469
// CHECK: sil_vtable RequiredInitDerived {
13570
// CHECK-NEXT: #SimpleInitBase.init!initializer.1: {{.*}} : _T07vtables19RequiredInitDerivedC{{[_0-9a-zA-Z]*}}fc
13671
// CHECK-NEXT #RequiredInitDerived.init!allocator.1: {{.*}} : _TFC7vtables19RequiredInitDerivedC

test/SILGen/vtables_objc.swift

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// RUN: %target-swift-frontend -sdk %S/Inputs -emit-silgen -I %S/Inputs -enable-source-import %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
import gizmo
6+
7+
// Test ObjC base class
8+
9+
class Hoozit : Gizmo {
10+
// Overrides Gizmo.frob
11+
override func frob() {}
12+
13+
// Overrides Gizmo.funge
14+
override func funge() {}
15+
16+
// Overrides Gizmo.foo
17+
final override func foo() {}
18+
19+
func anse() {}
20+
func incorrige() {}
21+
}
22+
23+
// CHECK-LABEL: sil hidden @_T012vtables_objc10callHoozityAA0D0CF : $@convention(thin) (@owned Hoozit) -> ()
24+
func callHoozit(_ h: Hoozit) {
25+
// CHECK: class_method [volatile] {{.*}} : $Hoozit, #Hoozit.frob!1.foreign
26+
h.frob()
27+
// CHECK: function_ref @_T012vtables_objc6HoozitC3fooyyF
28+
h.foo()
29+
// CHECK: class_method {{.*}} : $Hoozit, #Hoozit.anse!1
30+
h.anse()
31+
// CHECK: return
32+
}
33+
34+
class Wotsit : Hoozit {
35+
// Overrides Gizmo.funge
36+
override func funge() {}
37+
38+
// Overrides Hoozit.incorrige
39+
override func incorrige() {}
40+
41+
// Overrides Gizmo.frob
42+
final override func frob() {}
43+
}
44+
45+
// CHECK-LABEL: sil hidden @_T012vtables_objc10callWotsityAA0D0CF : $@convention(thin) (@owned Wotsit) -> ()
46+
func callWotsit(_ w: Wotsit) {
47+
// CHECK: class_method [volatile] {{.*}} : $Wotsit, #Wotsit.funge!1.foreign
48+
w.funge()
49+
// CHECK: class_method {{.*}} : $Wotsit, #Wotsit.incorrige!1
50+
w.incorrige()
51+
// CHECK: function_ref @_T012vtables_objc6WotsitC4frobyyF
52+
w.frob()
53+
// CHECK: return
54+
}
55+
56+
// Entries only exist for native Swift methods
57+
58+
// CHECK: sil_vtable Hoozit {
59+
// CHECK-NEXT: #Hoozit.anse!1: {{.*}} : _T012vtables_objc6HoozitC4anse{{[_0-9a-zA-Z]*}}F
60+
// CHECK-NEXT: #Hoozit.incorrige!1: {{.*}} : _T012vtables_objc6HoozitC9incorrige{{[_0-9a-zA-Z]*}}F
61+
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> () -> Hoozit! : _T012vtables_objc6HoozitCSQyACGycfc
62+
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> (Int) -> Hoozit! : _T012vtables_objc6HoozitCSQyACGSi7bellsOn_tcfc
63+
// CHECK-NEXT: #Hoozit.deinit!deallocator: _T012vtables_objc6HoozitCfD
64+
// CHECK-NEXT: }
65+
66+
// CHECK: sil_vtable Wotsit {
67+
// CHECK-NEXT: #Hoozit.anse!1: {{.*}} : _T012vtables_objc6HoozitC4anse{{[_0-9a-zA-Z]*}}F
68+
// CHECK-NEXT: #Hoozit.incorrige!1: {{.*}} : _T012vtables_objc6WotsitC9incorrige{{[_0-9a-zA-Z]*}}F
69+
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> () -> Hoozit! : _T012vtables_objc6WotsitCSQyACGycfc
70+
// CHECK-NEXT: #Hoozit.init!initializer.1: (Hoozit.Type) -> (Int) -> Hoozit! : _T012vtables_objc6WotsitCSQyACGSi7bellsOn_tcfc
71+
// CHECK-NEXT: #Wotsit.deinit!deallocator: _T012vtables_objc6WotsitCfD
72+
// CHECK-NEXT: }
73+
74+
// <rdar://problem/15282548>
75+
// CHECK: sil_vtable Base {
76+
// CHECK: #Base.init!initializer.1: {{.*}} : _T012vtables_objc4BaseC{{[_0-9a-zA-Z]*}}fc
77+
// CHECK: }
78+
// CHECK: sil_vtable Derived {
79+
// CHECK: #Base.init!initializer.1: {{.*}} : _T012vtables_objc7DerivedC{{[_0-9a-zA-Z]*}}fc
80+
// CHECK: }
81+
@objc class Base {}
82+
83+
extension Base {
84+
// note: does not have a vtable slot, because it is from an extension
85+
func identify() -> Int {
86+
return 0
87+
}
88+
}
89+
90+
class Derived : Base {
91+
override func identify() -> Int {
92+
return 1
93+
}
94+
}

0 commit comments

Comments
 (0)