-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow anonymous enums to be imported as non-constants. #42223
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef TEST_INTEROP_CXX_ENUM_INPUTS_ANONYMOUS_WITH_SWIFT_NAME_H | ||
#define TEST_INTEROP_CXX_ENUM_INPUTS_ANONYMOUS_WITH_SWIFT_NAME_H | ||
|
||
#define SOME_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum __attribute__((flag_enum,enum_extensibility(open))) : _name | ||
#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum : _name | ||
|
||
typedef SOME_OPTIONS(unsigned, SOColorMask) { | ||
kSOColorMaskRed = (1 << 1), | ||
kSOColorMaskGreen = (1 << 2), | ||
kSOColorMaskBlue = (1 << 3), | ||
kSOColorMaskAll = ~0U | ||
}; | ||
|
||
|
||
typedef CF_OPTIONS(unsigned, CFColorMask) { | ||
kCFColorMaskRed = (1 << 1), | ||
kCFColorMaskGreen = (1 << 2), | ||
kCFColorMaskBlue = (1 << 3), | ||
kCFColorMaskAll = ~0U | ||
}; | ||
|
||
#endif // TEST_INTEROP_CXX_ENUM_INPUTS_ANONYMOUS_WITH_SWIFT_NAME_H |
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
55 changes: 55 additions & 0 deletions
55
test/Interop/Cxx/enum/anonymous-with-swift-name-module-interface.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,55 @@ | ||
// RUN: %target-swift-ide-test -print-module -module-to-print=AnonymousWithSwiftName -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s | ||
|
||
// CHECK: @available(*, unavailable, message: "Not available in Swift") | ||
// CHECK: typealias SOColorMask = UInt32 | ||
|
||
// CHECK: struct SOColorMask : OptionSet, @unchecked Sendable { | ||
// CHECK: init(rawValue: UInt32) | ||
// CHECK: let rawValue: UInt32 | ||
// CHECK: typealias RawValue = UInt32 | ||
// CHECK: typealias Element = SOColorMask | ||
// CHECK: typealias ArrayLiteralElement = SOColorMask | ||
|
||
// CHECK: static var red: SOColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "red") | ||
// CHECK: static var Red: SOColorMask { get } | ||
|
||
// CHECK: static var green: SOColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "green") | ||
// CHECK: static var Green: SOColorMask { get } | ||
|
||
// CHECK: static var blue: SOColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "blue") | ||
// CHECK: static var Blue: SOColorMask { get } | ||
|
||
// CHECK: static var all: SOColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "all") | ||
// CHECK: static var All: SOColorMask { get } | ||
// CHECK: } | ||
|
||
// CHECK: @available(*, unavailable, message: "Not available in Swift") | ||
// CHECK: typealias CFColorMask = UInt32 | ||
|
||
// CHECK: struct CFColorMask : OptionSet { | ||
// CHECK: init(rawValue: UInt32) | ||
// CHECK: let rawValue: UInt32 | ||
// CHECK: typealias RawValue = UInt32 | ||
// CHECK: typealias Element = CFColorMask | ||
// CHECK: typealias ArrayLiteralElement = CFColorMask | ||
|
||
// CHECK: static var red: CFColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "red") | ||
// CHECK: static var Red: CFColorMask { get } | ||
|
||
// CHECK: static var green: CFColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "green") | ||
// CHECK: static var Green: CFColorMask { get } | ||
|
||
// CHECK: static var blue: CFColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "blue") | ||
// CHECK: static var Blue: CFColorMask { get } | ||
|
||
// CHECK: static var all: CFColorMask { get } | ||
// CHECK: @available(swift, obsoleted: 3, renamed: "all") | ||
// CHECK: static var All: CFColorMask { get } | ||
// CHECK: } |
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,34 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop) | ||
|
||
// REQUIRES: executable_test | ||
|
||
import AnonymousWithSwiftName | ||
import StdlibUnittest | ||
|
||
var AnonymousEnumsTestSuite = TestSuite("Anonymous Enums With Swift Name") | ||
|
||
AnonymousEnumsTestSuite.test("SOME_OPTIONS") { | ||
let red: SOColorMask = .red | ||
let green = SOColorMask.green | ||
let blue = .blue as SOColorMask | ||
let all: SOColorMask = .all | ||
|
||
expectEqual(red.rawValue, 2) | ||
expectEqual(green.rawValue, 4) | ||
expectEqual(blue.rawValue, 8) | ||
expectEqual(all.rawValue, ~CUnsignedInt(0)) | ||
} | ||
|
||
AnonymousEnumsTestSuite.test("CF_OPTIONS") { | ||
let red: SOColorMask = .red | ||
let green = SOColorMask.green | ||
let blue = .blue as SOColorMask | ||
let all: SOColorMask = .all | ||
|
||
expectEqual(red.rawValue, 2) | ||
expectEqual(green.rawValue, 4) | ||
expectEqual(blue.rawValue, 8) | ||
expectEqual(all.rawValue, ~CUnsignedInt(0)) | ||
} | ||
|
||
runAllTests() |
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.
These need to be CF
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.
Fixed in: 1d74713