Skip to content

Remove an old restriction on _ObjectiveCBridgeable conformances. #71426

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
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
4 changes: 0 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -6310,10 +6310,6 @@ ERROR(objc_ambiguous_error_convention,none,
NOTE(objc_ambiguous_error_convention_candidate,none,
"%0 provides an error argument here", (const ValueDecl *))

ERROR(nonlocal_bridged_to_objc,none,
"conformance of %0 to %1 can only be written in module %2",
(Identifier, Identifier, Identifier))

ERROR(missing_bridging_function,Fatal,
"missing '%select{_forceBridgeFromObjectiveC|"
"_conditionallyBridgeFromObjectiveC}0'", (bool))
Expand Down
23 changes: 0 additions & 23 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2389,29 +2389,6 @@ checkIndividualConformance(NormalProtocolConformance *conformance) {
}
}

// Except in specific hardcoded cases for Foundation/Swift
// standard library compatibility, an _ObjectiveCBridgeable
// conformance must appear in the same module as the definition of
// the conforming type.
//
// Note that we check the module name to smooth over the difference
// between an imported Objective-C module and its overlay.
if (Proto->isSpecificProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
auto nominal = DC->getSelfNominalTypeDecl();
if (!Context.isTypeBridgedInExternalModule(nominal)) {
auto clangLoader = Context.getClangModuleLoader();
if (nominal->getParentModule() != DC->getParentModule() &&
!(clangLoader &&
clangLoader->isInOverlayModuleForImportedModule(DC, nominal))) {
auto nominalModule = nominal->getParentModule();
Context.Diags.diagnose(conformance->getLoc(),
diag::nonlocal_bridged_to_objc,
nominal->getName(), Proto->getName(),
nominalModule->getName());
}
}
}

// Check that T conforms to all inherited protocols.
for (auto InheritedProto : Proto->getInheritedProtocols()) {
auto InheritedConformance =
Expand Down
7 changes: 4 additions & 3 deletions test/Constraints/bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public class BridgedClass : NSObject, NSCopying {

public class BridgedClassSub : BridgedClass { }

// Attempt to bridge to a type from another module. We only allow this for a
// few specific types, like String.
extension LazyFilterSequence.Iterator : @retroactive _ObjectiveCBridgeable { // expected-error{{conformance of 'Iterator' to '_ObjectiveCBridgeable' can only be written in module 'Swift'}}
// Attempt to bridge to a type from another module.
// We used to work hard to prevent this, but doing so was getting in the
// way of layering for the swift-foundation project.
extension LazyFilterSequence.Iterator : @retroactive _ObjectiveCBridgeable {
public typealias _ObjectiveCType = BridgedClassSub

public func _bridgeToObjectiveC() -> _ObjectiveCType {
Expand Down