Files
swift-mirror/test/SILGen/win_bool_bridging.swift
Saleem Abdulrasool 83b290438c Windows: bridge BOOL to Bool
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.
2019-04-25 17:52:08 -07:00

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)