mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Inheritance of a protocol from JavaScriptCore's JSExport protocol is used to indicate that the methods and properties of that protocol should be exported to JavaScript. The actual check to determine whether a protocol (directly) inherits JSExport is performed via the Objective-C runtime. Note that the presence of JSExport in the protocol hierarchy is not sufficient; the protocol must directly inherit JSExport. Swift warns about redundant conformance requirements and eliminates them from the requirement signature (and, therefore, the Objective-C metadata). This behavior is incorrect for JSExport, because the conformance is actually needed for this API to work properly. Recognize a protocol's inheritance JSExport specifically (by name) when computing the requirement signature of the protocol. When we find such a redundancy, suppress the "redundant conformance constraint" diagnostic and add a new (hidden) attribute @_restatedObjCConformance(proto). The attribute is used only by Objective-C protocol metadata emission to ensure that we get the expected metadata in the Objective-C runtime. Fixes rdar://problem/32674145.
22 lines
829 B
Swift
22 lines
829 B
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/abi %s -emit-ir | %FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
import Foundation
|
|
|
|
@objc protocol JSExport { }
|
|
|
|
@objc protocol RootJSExport : JSExport { }
|
|
|
|
// CHECK: @_PROTOCOL_PROTOCOLS__TtP8JSExport4Sub1_ = private constant{{.*}}_PROTOCOL__TtP8JSExport12RootJSExport_{{.*}}_PROTOCOL__TtP8JSExport8JSExport_
|
|
@objc protocol Sub1 : JSExport, RootJSExport { }
|
|
|
|
// CHECK: @_PROTOCOL_PROTOCOLS__TtP8JSExport4Sub2_{{.*}}_PROTOCOL__TtP8JSExport4Sub1_{{.*}}_PROTOCOL__TtP8JSExport8JSExport_
|
|
@objc protocol Sub2 : Sub1, JSExport { }
|
|
|
|
// CHECK: @_PROTOCOL_PROTOCOLS__TtP8JSExport4Sub3_ = private constant{{.*}}@_PROTOCOL__TtP8JSExport4Sub2_
|
|
@objc protocol Sub3 : Sub2 { }
|
|
|
|
protocol ReexportJSExport : RootJSExport, JSExport { }
|