Files
swift-mirror/test/Parse/closure-missing-in.swift
Kwiky 164887b27d [Parse] Diagnose missing 'in' after closure signature
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
2025-10-03 20:42:19 +02:00

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 }
}