mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This moves trailing closures from expr-postfix up to the level of expr, and introduces an intermediate level (expr-basic) for places that need to parse expressions followed by curly braces, such as if/while/switch/for. Trailing closures are still restricted to occur after expr-postfix, although the parser itself parses a slightly more general and then complains if it got more than an expr-postfix. Swift SVN r5256
38 lines
1.1 KiB
Swift
38 lines
1.1 KiB
Swift
// RUN: %swift -parse %s -verify
|
|
|
|
func takeFunc(f : (Int) -> Int) -> Int {}
|
|
func takeValueAndFunc(value : Int, f : (Int) -> Int) {}
|
|
func takeTwoFuncs(f : (Int) -> Int, g : (Int) -> Int) {}
|
|
|
|
struct X {
|
|
func takeFunc(f : (Int) -> Int) {}
|
|
func takeValueAndFunc(value : Int, f : (Int) -> Int) {}
|
|
func takeTwoFuncs(f : (Int) -> Int, g : (Int) -> Int) {}
|
|
}
|
|
|
|
func addToMemberCalls(x : X) {
|
|
x.takeFunc() { |x| x }
|
|
x.takeFunc() { $0 }
|
|
x.takeValueAndFunc(1) { |x| x }
|
|
x.takeValueAndFunc(value : 1) { |x| x }
|
|
x.takeTwoFuncs() { |x| x } { |y| y }
|
|
}
|
|
|
|
func addToCalls() {
|
|
takeFunc() { |x| x }
|
|
takeFunc() { $0 }
|
|
takeValueAndFunc(1) { |x| x }
|
|
takeValueAndFunc(value : 1) { |x| x }
|
|
takeTwoFuncs() { |x| x } { |y| y }
|
|
}
|
|
|
|
func makeCalls() {
|
|
takeFunc { |x| x }
|
|
takeFunc { $0 }
|
|
takeTwoFuncs { |x| x } { |y| y }
|
|
}
|
|
|
|
func notPostfix() {
|
|
1 + takeFunc { $0 } // expected-error{{trailing closure can only follow a postfix expression}} expected-note{{complete expression}}{3-3:(}{14-4:)} expected-note{{last postfix}}{7-7:(}{21-21:)} expected-error{{does not type-check}}
|
|
}
|