Files
swift-mirror/test/Interpreter/switch_where_clause.swift
Joe Groff dfdece2ab6 SILGen: Push 'usingImplicitVariablesForPattern' hack into 'where' clause expr evaluation.
We swapped the pattern variables at the wrong level, leaving them bound incorrectly on the cleanup path through a failed 'where' clause check. Fixes rdar://problem/31539726.
2017-04-14 11:58:38 -07:00

38 lines
1.1 KiB
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
func boo(_: LifetimeTracked) -> Bool { return true }
var tests = TestSuite("switches with where clauses")
enum Foo {
case a(LifetimeTracked)
case b(LifetimeTracked)
}
func foo(_ x: Foo, _ y: Foo, _ condition: (LifetimeTracked) -> Bool) -> Bool {
switch (x, y) {
case (.a(let xml), _),
(_, .a(let xml)) where condition(xml):
return true
default:
return false
}
}
tests.test("all paths through a switch with guard") {
_ = foo(.a(LifetimeTracked(0)), .a(LifetimeTracked(1)), { _ in true })
_ = foo(.a(LifetimeTracked(2)), .b(LifetimeTracked(3)), { _ in true })
_ = foo(.b(LifetimeTracked(4)), .a(LifetimeTracked(5)), { _ in true })
_ = foo(.b(LifetimeTracked(6)), .b(LifetimeTracked(7)), { _ in true })
_ = foo(.a(LifetimeTracked(10)), .a(LifetimeTracked(11)), { _ in false })
_ = foo(.a(LifetimeTracked(12)), .b(LifetimeTracked(13)), { _ in false })
_ = foo(.b(LifetimeTracked(14)), .a(LifetimeTracked(15)), { _ in false })
_ = foo(.b(LifetimeTracked(16)), .b(LifetimeTracked(17)), { _ in false })
}
runAllTests()