Skip to content

Commit 8159c84

Browse files
committed
Sema: "super" calls to non-ObjC extension methods must be statically dispatched.
They currently can't ever show up in the vtable, so we must emit static calls to them. Fixes rdar://problem/30030229.
1 parent 2ad2e25 commit 8159c84

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ static bool canUseStaticDispatch(SILGenFunction &gen,
117117

118118
if (funcDecl->isFinal())
119119
return true;
120+
// Extension methods currently must be statically dispatched, unless they're
121+
// @objc or dynamic.
122+
if (funcDecl->getDeclContext()->isExtensionContext()
123+
&& !constant.isForeign)
124+
return true;
120125

121126
// We cannot form a direct reference to a method body defined in
122127
// Objective-C.

test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ extension NSDictionary {
355355
@objc(_swift_objectForKeyedSubscript:)
356356
get { fatalError() }
357357
}
358+
359+
public func nonObjCExtensionMethod<T>(_: T) {}
358360
}
359361
extension NSMutableDictionary {
360362
public override subscript(_: Any) -> Any? {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
// rdar://problem/30030229
5+
6+
import Foundation
7+
8+
class MyDictionary: NSDictionary {
9+
// CHECK-LABEL: sil hidden @_TFC4main12MyDictionary31callSuperNonObjCExtensionMethodfSiT_
10+
func callSuperNonObjCExtensionMethod(_ x: Int) {
11+
// CHECK-NOT: super_method {{.*}} #NSDictionary.nonObjCExtensionMethod
12+
super.nonObjCExtensionMethod(x)
13+
}
14+
}

0 commit comments

Comments
 (0)