Files
swift-mirror/test/Constraints/patterns.swift
Joe Groff efd1cf47ca Parse patterns in expression position as UnboundPatternExprs.
Parse patterns as top-level expression productions, for name binding to validate and convert into proper patterns later. If the type-checker sees an UnboundPattern production survive name binding (currently always), then raise a helpful "patterns don't belong here" error.

Swift SVN r5842
2013-06-27 20:38:39 +00:00

13 lines
557 B
Swift

// RUN: %swift -parse -verify %s
// Raise an error if pattern productions are used in expressions.
var a = _ // expected-error{{'_' pattern cannot appear in an expression}}
var b = var a // expected-error{{'var' binding pattern cannot appear in an expression}}
var c = is Int // expected-error{{prefix 'is' pattern cannot appear in an expression}}
// TODO: Bad recovery in these cases. Although patterns are never valid
// expr-unary productions, it would be good to parse them anyway for recovery.
//var d = _ + 1
//var e = 2 + var y
//var e = var y + 2