mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
30
test/Parse/matching_patterns.swift
Normal file
30
test/Parse/matching_patterns.swift
Normal 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):
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user