Files
swift-mirror/test/Constraints/implicit_last_exprs_double_cgfloat_conversion.swift
Hamish Knight 7b4c9fef02 Allow implicit last expressions for functions and closures
Gated behind the experimental feature
`ImplicitLastExprResults`.
2024-02-07 18:14:23 +00:00

65 lines
1.0 KiB
Swift

// RUN: %target-typecheck-verify-swift -enable-experimental-feature ImplicitLastExprResults %clang-importer-sdk
// REQUIRES: objc_interop
// Experimental feature requires asserts
// REQUIRES: asserts
import Foundation
func testReturn1(_ d: Double) -> CGFloat {
print("hello")
d
}
func testReturn2(_ d: Double) -> CGFloat {
()
if .random() { d } else { 0 }
}
func testReturn3(_ d: CGFloat) -> Double {
print("hello")
switch Bool.random() { case true: d case false: 0 }
}
func testReturn4(_ d: Double) -> CGFloat {
print("hello")
if .random() {
print("hello")
d
} else {
if .random() {
print("hello")
d
} else {
0
}
}
}
func testClosure(_ d: CGFloat) {
func fn(_: () -> Double) {}
fn {
print("hello")
d
}
fn {
print("hello")
if .random() { 0.0 } else { d }
}
fn {
print("hello")
if .random() {
print("hello")
d
} else {
if .random() {
print("hello")
d
} else {
0
}
}
}
}