mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
importer::findOptionSetEnum() uses some fragile heuristics to determine
whether a typedef is involved in the construction of a CF_OPTIONS or
NS_OPTIONS type. This patch adds an explicit check that the typedef is
expanded from either of those macros, to prevent, e.g., an unavailable
NS_ENUM, from being mistakenly recognized as an NS_OPTIONS.
Note that doing this is still kind of fragile, and prevents users from
building {NS,CF}_OPTIONS with their own macros. The right thing to do is
probably specifically look for the flag_enum attribute, but that is not
currently what we're doing for reasons whose discovery is left as
an exercise to the future git archaeologist.
This patch also removes (part of) a test case that builds
a CF_OPTIONS-like type with the "SOME_OPTIONS" macro, which is no longer
supported as of this patch.
rdar://150399978
44 lines
1.1 KiB
Swift
44 lines
1.1 KiB
Swift
// 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("CF_OPTIONS") {
|
|
let red: CFColorMask = .red
|
|
let green = CFColorMask.green
|
|
let blue = .blue as CFColorMask
|
|
let all: CFColorMask = .all
|
|
|
|
expectEqual(red.rawValue, 2)
|
|
expectEqual(green.rawValue, 4)
|
|
expectEqual(blue.rawValue, 8)
|
|
expectEqual(all.rawValue, ~CUnsignedInt(0))
|
|
}
|
|
|
|
AnonymousEnumsTestSuite.test("Parameter types") {
|
|
let red: CFColorMask = .red
|
|
let green = CFColorMask.green
|
|
|
|
let blue = useCFColorMask(.blue)
|
|
let all = useCFColorMask(.all)
|
|
|
|
expectEqual(red, useCFColorMask(.red))
|
|
expectEqual(green, useCFColorMask(.green))
|
|
expectEqual(blue, .blue)
|
|
expectEqual(all, .all)
|
|
}
|
|
|
|
AnonymousEnumsTestSuite.test("Computed properties") {
|
|
let parent = ParentStruct()
|
|
|
|
expectEqual(parent.colorProp, useCFColorMask(.red))
|
|
parent.colorProp = .green
|
|
expectEqual(parent.colorProp, useCFColorMask(.red))
|
|
}
|
|
|
|
runAllTests()
|