Skip to content

Sema: "super" calls to non-ObjC extension methods must be statically dispatched. #7167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ static bool canUseStaticDispatch(SILGenFunction &gen,

if (funcDecl->isFinal())
return true;
// Extension methods currently must be statically dispatched, unless they're
// @objc or dynamic.
if (funcDecl->getDeclContext()->isExtensionContext()
&& !constant.isForeign)
return true;

// We cannot form a direct reference to a method body defined in
// Objective-C.
Expand Down
2 changes: 2 additions & 0 deletions test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ extension NSDictionary {
@objc(_swift_objectForKeyedSubscript:)
get { fatalError() }
}

public func nonObjCExtensionMethod<T>(_: T) {}
}
extension NSMutableDictionary {
public override subscript(_: Any) -> Any? {
Expand Down
14 changes: 14 additions & 0 deletions test/SILGen/super-to-nonobjc-extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen %s | %FileCheck %s
// REQUIRES: objc_interop

// rdar://problem/30030229

import Foundation

class MyDictionary: NSDictionary {
// CHECK-LABEL: sil hidden @_TFC4main12MyDictionary31callSuperNonObjCExtensionMethodfSiT_
func callSuperNonObjCExtensionMethod(_ x: Int) {
// CHECK-NOT: super_method {{.*}} #NSDictionary.nonObjCExtensionMethod
super.nonObjCExtensionMethod(x)
}
}