mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Previously we would only do source ordering for ClosureExprs, but other conjunctions need to have their source location taken into account too, in order to make sure we don't try and type-check e.g a TapExpr in a second closure before we type-check the first closure. Also while here, switch to `std::min_element` instead of sorting, and treat invalid source locations as incomparable. rdar://113326835
47 lines
1.0 KiB
Swift
47 lines
1.0 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
// rdar://113326835 - Make sure we type-check the conjunctions in source order,
|
|
// the first closure should be type-checked before we attempt the
|
|
// TapExpr/SingleValueExpr conjunctions, since they rely on 'k' being resolved.
|
|
|
|
func global<T>(_ x: T) -> String { "" }
|
|
func global(_ x: Any.Type) -> String { "" }
|
|
|
|
protocol P {
|
|
associatedtype X
|
|
}
|
|
|
|
struct Q<X>: P {
|
|
init() {}
|
|
func bar(_: String) -> Self { fatalError() }
|
|
func qux<U: P>(_: (X) -> U) -> Q<U.X> { fatalError() }
|
|
}
|
|
|
|
struct J<X>: P {
|
|
init(_: X) {}
|
|
func baz<T>(_ transform: (X) -> T) -> Q<T> { fatalError() }
|
|
}
|
|
|
|
func foo(a: Int) -> Q<String> {
|
|
J(a)
|
|
.baz { x in
|
|
()
|
|
return a
|
|
}
|
|
.qux { k in
|
|
Q<String>().bar("\(k)")
|
|
}
|
|
}
|
|
|
|
func bar(a: Int) -> Q<String> {
|
|
J(a)
|
|
.baz { x in
|
|
()
|
|
return a
|
|
}
|
|
.qux { k in
|
|
Q<String>().bar(if .random() { global(k) } else { global(k) })
|
|
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
|
|
}
|
|
}
|