mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Find all the usages of `--enable-experimental-feature` or `--enable-upcoming-feature` in the tests and replace some of the `REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which should correctly apply to depending on the asserts/noasserts mode of the toolchain for each feature. Remove some comments that talked about enabling asserts since they don't apply anymore (but I might had miss some). All this was done with an automated script, so some formatting weirdness might happen, but I hope I fixed most of those. There might be some tests that were `REQUIRES: asserts` that might run in `noasserts` toolchains now. This will normally be because their feature went from experimental to upcoming/base and the tests were not updated.
109 lines
2.5 KiB
Swift
109 lines
2.5 KiB
Swift
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ThenStatements
|
|
|
|
// REQUIRES: swift_feature_ThenStatements
|
|
|
|
enum E {
|
|
case e
|
|
case f
|
|
case g(Int)
|
|
}
|
|
|
|
func testVoidNeverConversion() {
|
|
// Explicit 'then' statements don't participate in implicit Void/Never conversions.
|
|
let _: () -> Void = {
|
|
if .random() {
|
|
then 0 // expected-error {{cannot convert value of type 'Int' to specified type 'Void'}}
|
|
} else {
|
|
0
|
|
}
|
|
}
|
|
let _: () -> Void = {
|
|
if .random() {
|
|
then fatalError() // expected-error {{cannot convert value of type 'Never' to specified type 'Void'}}
|
|
} else {
|
|
0
|
|
}
|
|
}
|
|
let _ = {
|
|
if .random() {
|
|
then "" // expected-error {{branches have mismatching types 'String' and 'Int'}}
|
|
} else {
|
|
then 0
|
|
}
|
|
}
|
|
let _ = {
|
|
if .random() {
|
|
then ()
|
|
} else {
|
|
0 // expected-warning {{integer literal is unused}}
|
|
}
|
|
}
|
|
let _ = {
|
|
if .random() {
|
|
then ""
|
|
} else {
|
|
fatalError()
|
|
}
|
|
}
|
|
func foo() -> Int {
|
|
switch Bool.random() {
|
|
case true:
|
|
fatalError()
|
|
case false:
|
|
then fatalError() // expected-error {{cannot convert value of type 'Never' to specified type 'Int'}}
|
|
}
|
|
}
|
|
}
|
|
|
|
enum Either<T, U> {
|
|
case first(T), second(U)
|
|
}
|
|
|
|
@resultBuilder
|
|
struct Builder { // expected-note 2{{struct 'Builder' declared here}}
|
|
static func buildBlock<T>(_ x: T) -> T { x }
|
|
static func buildBlock<T, U>(_ x: T, _ y: U) -> (T, U) { (x, y) }
|
|
|
|
static func buildEither<T, U>(first x: T) -> Either<T, U> { .first(x) }
|
|
static func buildEither<T, U>(second x: U) -> Either<T, U> { .second(x) }
|
|
|
|
static func buildExpression(_ x: Double) -> Double { x }
|
|
static func buildExpression<T>(_ x: T) -> T { x }
|
|
}
|
|
|
|
@Builder
|
|
func testThenStmtBuilder1() -> Either<Int, Int> {
|
|
// We don't allow explicit 'then' to be part of the transform.
|
|
if .random() {
|
|
then 0 // expected-error {{closure containing control flow statement cannot be used with result builder 'Builder'}}
|
|
} else {
|
|
1
|
|
}
|
|
}
|
|
|
|
@Builder
|
|
func testThenStmtBuilder2() -> Either<Int, Int> {
|
|
// We don't allow explicit 'then' to be part of the transform.
|
|
if .random() {
|
|
then 0 // expected-error {{closure containing control flow statement cannot be used with result builder 'Builder'}}
|
|
} else {
|
|
1
|
|
}
|
|
()
|
|
}
|
|
|
|
@Builder
|
|
func testThenStmtBuilder3() -> Either<Int, String> {
|
|
// But it's fine as part of e.g a binding.
|
|
let x = if .random() {
|
|
then 0
|
|
} else {
|
|
1
|
|
}
|
|
if .random() {
|
|
x
|
|
} else {
|
|
""
|
|
}
|
|
}
|