mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Now that SILGen and IRGen can both handle capturing archetypes from generic scopes, we can set the DeclContext of ImplicitClosureExprs correctly, so that SILGen captures their context archetypes. &&, and ||, and assert now work in generic contexts, at least in simple test cases. Swift SVN r5476
35 lines
673 B
Swift
35 lines
673 B
Swift
// RUN: %swift -i %s | FileCheck %s
|
|
|
|
func andc<T:LogicValue>(x:Bool, y:T) -> Bool {
|
|
return x && !y.getLogicValue()
|
|
}
|
|
|
|
struct Truthy : LogicValue {
|
|
func getLogicValue() -> Bool {
|
|
return true
|
|
}
|
|
}
|
|
|
|
struct Falselike : LogicValue {
|
|
func getLogicValue() -> Bool {
|
|
return false
|
|
}
|
|
}
|
|
|
|
println(andc(true, Truthy())) // CHECK: false
|
|
println(andc(false, Truthy())) // CHECK: false
|
|
println(andc(true, Falselike())) // CHECK: true
|
|
println(andc(false, Falselike())) // CHECK: false
|
|
|
|
func must<T:LogicValue>(x:T) {
|
|
assert(x.getLogicValue())
|
|
}
|
|
func shant<T:LogicValue>(x:T) {
|
|
assert(!x.getLogicValue())
|
|
}
|
|
|
|
must(Truthy())
|
|
shant(Falselike())
|
|
|
|
println("ok") // CHECK: ok
|