Files
swift-mirror/test/Constraints/condition.swift
Doug Gregor d6ca87b614 [Constraint checker] Implement typeCheckCondition() with a constraint system.
Introduce the LogicValue protocol, which is used to establish when a
particular type can be used as a logical value in a condition. Make
Bool conform to this protocol.

Rename the Builtin.i1-returning Bool.getLogicValue() to
_getBuiltinLogicValue(), because this is meant to be a builtin hook
for the compiler. We can add more underscores here if needed to hide
this further from users. 

Move the implementation of _getBool() into C code. It was performing
an 'if' on a Builtin.i1, which does not (and should not!) conform to
the LogicValue protocol. Once more oneof IR generation comes online,
we'll be able to write both this and _getBuiltinLogicValue in Swift
directly.



Swift SVN r5140
2013-05-10 15:42:41 +00:00

30 lines
558 B
Swift

// RUN: %swift -parse %s -verify
// Basic support for Bool
func simpleIf(b : Bool) {
if b { }
}
// Support for non-Bool logic values
struct OtherLogicValue : LogicValue {
func getLogicValue() -> Bool { return true }
}
func otherIf(b : OtherLogicValue) {
if b { }
}
// Support for arbitrary logic values in generics
func doIf<T : LogicValue>(t : T) {
if t { }
}
doIf(true)
// Using LogicValue-ness to resolve overloading.
func getValue() -> OtherLogicValue {}
func getValue() -> Int {}
func testLogicValueOverloading() {
if getValue() { }
}