-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[interop] Prohibit use of C++ APIs in public interfaces that opt-in i… #65129
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
test/Interop/Cxx/library-evolution/allow-objc-in-cxx-mode-in-evolving-libraries.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: split-file %s %t | ||
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -typecheck -enable-library-evolution -enable-experimental-cxx-interop -verify | ||
|
||
// REQUIRES: objc_interop | ||
|
||
//--- Inputs/module.modulemap | ||
module ObjCxxModule { | ||
header "header.h" | ||
requires cplusplus | ||
} | ||
|
||
//--- Inputs/header.h | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
class CxxStruct { | ||
public: | ||
int x; int y; | ||
|
||
void method() const; | ||
}; | ||
|
||
@interface ObjCClass: NSObject | ||
|
||
- (void)myTestMethod; | ||
- (int *)returnsIntPtr; | ||
|
||
- (CxxStruct)testMethodReturnsCxxStruct; | ||
- (void)testMethodTakesCxxStructPtr: (CxxStruct * _Nullable) ptr; | ||
+ (ObjCClass * _Nonnull)getInstance; | ||
|
||
@property int intProp; | ||
@property(copy) ObjCClass * _Nonnull objcClassProp; | ||
@property CxxStruct * structPtrProp; | ||
|
||
@end | ||
|
||
using ObjCClassTypealias = ObjCClass * _Nonnull; | ||
|
||
@protocol ObjCProto | ||
|
||
- (void)testProto; | ||
|
||
@end | ||
|
||
using QualIDTypeAlias = id<ObjCProto>; | ||
|
||
using BuiltinIntTypealis = int; | ||
|
||
//--- test.swift | ||
|
||
import ObjCxxModule | ||
|
||
// ok | ||
public func usesObjCClass() -> ObjCClass { | ||
return ObjCClass.getInstance() | ||
} | ||
|
||
public func usesObjCClassTypealias(_ x: ObjCClassTypealias) { | ||
} | ||
|
||
public func usesObjCProto(_ x: ObjCProto) { | ||
} | ||
|
||
public func usesQualIDTypeAlias(_ x: QualIDTypeAlias) { | ||
} | ||
|
||
public func usesBuiltinIntTypealis() -> BuiltinIntTypealis { | ||
return 21 | ||
} | ||
|
||
@inlinable | ||
public func publicFuncPublicBody() { | ||
let i = ObjCClass.getInstance() | ||
i.myTestMethod() | ||
i.returnsIntPtr() | ||
let _ = i.intProp | ||
let _ = i.objcClassProp | ||
// expected-error@+1 {{instance method 'testMethodReturnsCxxStruct()' cannot be used in an '@inlinable' function because C++ APIs from imported module 'ObjCxxModule' do not support library evolution}} | ||
i.testMethodReturnsCxxStruct() | ||
// expected-error@+1 {{instance method 'testMethodTakesCxxStructPtr' cannot be used in an '@inlinable' function because C++ APIs from imported module 'ObjCxxModule' do not support library evolution}} | ||
i.testMethodTakesCxxStructPtr(nil) | ||
// expected-error@+1 {{property 'structPtrProp' cannot be used in an '@inlinable' function because C++ APIs from imported module 'ObjCxxModule' do not support library evolution}} | ||
let _ = i.structPtrProp | ||
} | ||
|
||
// expected-error@+1 {{cannot use struct 'CxxStruct' here; C++ types from imported module 'ObjCxxModule' do not support library evolution}} | ||
public func usesCxxStruct(_ x: CxxStruct) { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor typo:
whose
->whose type