Parse matching pattern specific productions at top level.

Parse 'var', '_', and 'is' pattern forms at the top level of a matching pattern context. Keep track of VarPatternDepth in the parser state and raise an error if 'var' appears in a 'var'.

Swift SVN r5839
This commit is contained in:
Joe Groff
2013-06-27 18:13:01 +00:00
parent 9efaf1ddc5
commit 675de63208
5 changed files with 107 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
// RUN: %swift -dump-parse -verify %s
var x:Int
func square(x:Int) -> Int { return x*x }
struct A<B> {
struct C<D> { }
}
switch x {
// Expressions as patterns.
case 0:
case 1 + 2:
case square(9):
// 'var' pattern.
case var a:
case var var a: // expected-error{{'var' cannot appear nested inside another 'var' pattern}}
// 'Any' pattern.
case _:
// 'is' pattern.
case is A<B>:
case is A<B>.C<D>:
case is (Int, Int):
case is (a:Int, b:Int):
}