Skip to content

Commit f2f9e2e

Browse files
committed
Sema: Fix assertion failure when overriding a dynamic method with a final method
Fixes <https://bugs.swift.org/browse/SR-5924>, <rdar://problem/34497670>.
1 parent 6a6a2b6 commit f2f9e2e

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
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_objc.swift

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,50 @@ import gizmo
99
class Hoozit : Gizmo {
1010
// Overrides Gizmo.frob
1111
override func frob() {}
12+
1213
// Overrides Gizmo.funge
1314
override func funge() {}
1415

16+
// Overrides Gizmo.foo
17+
final override func foo() {}
18+
1519
func anse() {}
1620
func incorrige() {}
1721
}
1822

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+
1956
// Entries only exist for native Swift methods
2057

2158
// CHECK: sil_vtable Hoozit {
@@ -26,11 +63,6 @@ class Hoozit : Gizmo {
2663
// CHECK-NEXT: #Hoozit.deinit!deallocator: _T012vtables_objc6HoozitCfD
2764
// CHECK-NEXT: }
2865

29-
class Wotsit : Hoozit {
30-
override func funge() {}
31-
override func incorrige() {}
32-
}
33-
3466
// CHECK: sil_vtable Wotsit {
3567
// CHECK-NEXT: #Hoozit.anse!1: {{.*}} : _T012vtables_objc6HoozitC4anse{{[_0-9a-zA-Z]*}}F
3668
// CHECK-NEXT: #Hoozit.incorrige!1: {{.*}} : _T012vtables_objc6WotsitC9incorrige{{[_0-9a-zA-Z]*}}F

0 commit comments

Comments
 (0)