Files
swift-mirror/test/Constraints/rdar114402042.swift
Hamish Knight 89a3390aa1 [Sema] Move SingleValueStmtUsageChecker into pre-checking
These diagnostics are better suited for pre-checking
since we ought to be emitting them even if there's
some other error with the expression.
2024-08-30 18:55:48 +01:00

33 lines
1.3 KiB
Swift

// RUN: %target-typecheck-verify-swift
// rdar://114402042 - Make sure we connect the SingleValueStmtExpr to the outer
// closure's return type.
func foo<T>(_: () -> T) {}
func bar<T>(_ x: T) {}
func test() {
foo {
bar(if true { return } else { return })
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
// expected-error@-2 2{{cannot use 'return' to transfer control out of 'if' expression}}
}
foo {
bar(if true { { return } } else { { return } })
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}
}
}
func baz() -> String? {
nil
}
var x: Int? = {
print( // expected-error {{cannot convert value of type '()' to closure result type 'Int?'}}
// expected-note@-1 {{to match this opening '('}}
switch baz() { // expected-error {{'switch' may only be used as expression in return, throw, or as the source of an assignment}}
case ""?:
return nil // expected-error {{cannot use 'return' to transfer control out of 'switch' expression}}
default:
return nil // expected-error {{cannot use 'return' to transfer control out of 'switch' expression}}
}
}() // expected-error {{expected ')' in expression list}}