Skip to content
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
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,12 @@ bool swift::diagnoseObjCMethodConflicts(SourceFile &sf) {
conflict.selector);
diag.warnUntilSwiftVersionIf(breakingInSwift5, 6);

// Temporarily soften selector conflicts in objcImpl extensions; we're
// seeing some that are caused by ObjCImplementationChecker improvements.
if (conflictingDecl->getDeclContext()->getImplementedObjCContext()
!= conflictingDecl->getDeclContext())
diag.wrapIn(diag::wrap_objc_implementation_will_become_error);

auto objcAttr = getObjCAttrIfFromAccessNote(conflictingDecl);
swift::softenIfAccessNote(conflictingDecl, objcAttr, diag);
if (objcAttr)
Expand Down
21 changes: 21 additions & 0 deletions test/decl/ext/Inputs/objc_implementation_class_extension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@import Foundation;

@interface ObjCClass : NSObject

- (void)methodFromHeader1:(int)param;
- (void)methodFromHeader2:(int)param;

@property (readwrite) int propertyFromHeader1;
@property (readwrite) int propertyFromHeader2;

@end

@interface ObjCClass ()

- (void)extensionMethodFromHeader1:(int)param;
- (void)extensionMethodFromHeader2:(int)param;

@property (readwrite) int extensionPropertyFromHeader1;
@property (readwrite) int extensionPropertyFromHeader2;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module objc_implementation_class_extension {
header "objc_implementation_class_extension.h"
export *
}

module objc_implementation_class_extension_internal {
header "objc_implementation_class_extension_internal.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import "objc_implementation_class_extension.h"

@interface ObjCClass ()

- (void)otherModuleExtensionMethodFromHeader1:(int)param;
- (void)otherModuleExtensionMethodFromHeader2:(int)param;

@property (readwrite) int otherModuleExtensionPropertyFromHeader1;
@property (readwrite) int otherModuleExtensionPropertyFromHeader2;

@end
33 changes: 33 additions & 0 deletions test/decl/ext/objc_implementation_class_extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -import-underlying-module -Xcc -fmodule-map-file=%S/Inputs/objc_implementation_class_extension.modulemap
// REQUIRES: objc_interop

@_implementationOnly import objc_implementation_class_extension_internal

@_objcImplementation extension ObjCClass {
// expected-warning@-1 {{extension for main class interface should provide implementation for instance method 'method(fromHeader2:)'}}
// expected-warning@-2 {{extension for main class interface should provide implementation for property 'propertyFromHeader2'}}
// expected-warning@-3 {{extension for main class interface should provide implementation for instance method 'otherModuleExtensionMethod(fromHeader2:)'}}
// expected-warning@-4 {{extension for main class interface should provide implementation for property 'otherModuleExtensionPropertyFromHeader2'}}
// expected-warning@-5 {{extension for main class interface should provide implementation for instance method 'extensionMethod(fromHeader2:)'}}
// expected-warning@-6 {{extension for main class interface should provide implementation for property 'extensionPropertyFromHeader2'}}

@objc func method(fromHeader1: CInt) {}
@objc private func method(fromHeader2: CInt) {}

@objc var propertyFromHeader1: CInt = 1
@objc private var propertyFromHeader2: CInt = 2

@objc func extensionMethod(fromHeader1: CInt) {}
@objc private func extensionMethod(fromHeader2: CInt) {}

@objc var extensionPropertyFromHeader1: CInt = 1
@objc private var extensionPropertyFromHeader2: CInt = 2

@objc func otherModuleExtensionMethod(fromHeader1: CInt) {}
@objc private func otherModuleExtensionMethod(fromHeader2: CInt) {}

@objc var otherModuleExtensionPropertyFromHeader1: CInt = 1
@objc private var otherModuleExtensionPropertyFromHeader2: CInt = 2
// expected-warning@-1 {{getter for 'otherModuleExtensionPropertyFromHeader2' with Objective-C selector 'otherModuleExtensionPropertyFromHeader2' conflicts with previous declaration with the same Objective-C selector}}
// expected-warning@-2 {{setter for 'otherModuleExtensionPropertyFromHeader2' with Objective-C selector 'setOtherModuleExtensionPropertyFromHeader2:' conflicts with previous declaration with the same Objective-C selector}}
}