mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Teach the parser to recognize a top-level '->' in a closure as a signature and
produce a targeted diagnostic ("expected 'in' after the closure signature")
instead of treating it as a type expression.
Adds a parser test:
- test/Parse/closure-missing-in.swift
Updates existing test with the new diagnostic:
- test/Parse/type_expr.swift
Resolves: swiftlang/swift#59928
30 lines
658 B
Swift
30 lines
658 B
Swift
// RUN: %target-swift-frontend -parse -verify -swift-version 5 %s
|
|
|
|
func test<T>(make: () -> [T], consume: (T) -> Void) { consume(make()[0]) }
|
|
|
|
func main1() {
|
|
test(make: { () -> [Int] // expected-error@+1 {{expected 'in' after the closure signature}}
|
|
return [3]
|
|
}, consume: { _ in })
|
|
}
|
|
|
|
|
|
// Resync path: there are tokens before `in` — should diagnose once, then recover.
|
|
func main2() {
|
|
_ = { () -> Int
|
|
0 // expected-error {{unexpected tokens prior to 'in'}}
|
|
in
|
|
1
|
|
}
|
|
}
|
|
|
|
func main3() {
|
|
_ = { x, y -> Int
|
|
x + y // expected-error {{expected 'in' after the closure signature}}
|
|
}
|
|
}
|
|
|
|
func ok() {
|
|
_ = { (x: Int) -> Int in x + 1 }
|
|
}
|