mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This allows the conversion of the Windows `BOOL` type to be converted to `Bool` implicitly. The implicit bridging allows for a more ergonomic use of the native Windows APIs in Swift. Due to the ambiguity between the Objective C `BOOL` and the Windows `BOOL`, we must manually map the `BOOL` type to the appropriate type. This required lifting the mapping entry for `ObjCBool` from the mapped types XMACRO definition into the inline definition in the importer. Take the opportunity to simplify the mapping code. Adjust the standard library usage of the `BOOL` type which is now eclipsed by the new `WindowsBool` type, preferring to use `Bool` whenever possible. Thanks to Jordan Rose for the suggestion to do this and a couple of hints along the way.
31 lines
630 B
Swift
31 lines
630 B
Swift
// RUN: %target-swift-frontend -typecheck %s -I %clang-importer-sdk-path/usr/include -verify
|
|
// REQUIRES: OS=windows-msvc
|
|
|
|
import WinSDK
|
|
import WinBOOL
|
|
|
|
func CheckToBool(_: Bool) {}
|
|
|
|
// Check `BOOL` to `Bool` conversion
|
|
CheckToBool(GetBOOL())
|
|
|
|
// Check passing `BOOL` to `BOOL`
|
|
TakeBOOL(GetBOOL())
|
|
|
|
// Check discarded assignment
|
|
_ = GetBOOL()
|
|
|
|
// Check assignment to `WinSDK.WindowsBool`
|
|
let b: WindowsBool = WindowsBool(GetBOOL())
|
|
|
|
// Check assignment to `Bool`
|
|
let v: Bool = GetBOOL()
|
|
|
|
// Check conversion from boolean literal to `BOOL`
|
|
TakeBOOL(true)
|
|
|
|
// Check conversion from `Bool` to `BOOL`
|
|
let f: Bool = false
|
|
TakeBOOL(f)
|
|
|