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.
108 lines
2.7 KiB
Swift
108 lines
2.7 KiB
Swift
// RUN: %target-swift-frontend -sil-verify-all -verify -emit-sil -enable-experimental-feature MoveOnlyEnumDeinits -enable-experimental-feature ConsumeSelfInDeinit %s
|
|
|
|
// REQUIRES: swift_feature_ConsumeSelfInDeinit
|
|
// REQUIRES: swift_feature_MoveOnlyEnumDeinits
|
|
|
|
|
|
func posix_close(_ t: Int) {}
|
|
|
|
struct GoodFileDescriptor: ~Copyable {
|
|
let _fd: Int = 0
|
|
|
|
var rawFileDescriptor: Int {
|
|
__consuming get {
|
|
let x = _fd
|
|
discard self
|
|
return x
|
|
}
|
|
}
|
|
|
|
__consuming func close() {
|
|
posix_close(_fd)
|
|
discard self
|
|
}
|
|
|
|
deinit {
|
|
close()
|
|
}
|
|
}
|
|
|
|
struct BadFileDescriptor: ~Copyable {
|
|
let _fd: Int = 0
|
|
|
|
deinit {}
|
|
|
|
var rawFileDescriptor: Int {
|
|
__consuming get { // expected-error {{'self' consumed more than once}}
|
|
discard self // expected-note {{consumed here}}
|
|
return self.rawFileDescriptor // expected-note {{consumed again here}}
|
|
// expected-warning@-1 {{function call causes an infinite recursion}}
|
|
}
|
|
}
|
|
|
|
__consuming func closeBoring(_ b: Bool) -> Int { // expected-error {{'self' consumed more than once}}
|
|
if b {
|
|
discard self // expected-note {{consumed here}}
|
|
}
|
|
return rawFileDescriptor // expected-note {{consumed again here}}
|
|
}
|
|
|
|
__consuming func closeRepeatedly(_ n: Int) -> Int { // expected-error {{'self' used after consume}}
|
|
for _ in 0..<n {
|
|
posix_close(_fd) // expected-note {{used here}}
|
|
discard self // expected-note {{consumed here}}
|
|
}
|
|
return 0
|
|
}
|
|
}
|
|
|
|
final class Wallet {
|
|
var ticket1: Ticket = .green
|
|
}
|
|
|
|
enum Ticket: ~Copyable {
|
|
case green
|
|
case yellow
|
|
case red
|
|
case pagedOut(GoodFileDescriptor)
|
|
case within(Wallet)
|
|
|
|
consuming func discard() { discard self }
|
|
|
|
init(inWallet wallet: Wallet? = nil) { // expected-error {{'self' consumed more than once}}
|
|
self = .within(Wallet())
|
|
if let existingWallet = wallet {
|
|
discard()
|
|
self = .within(existingWallet)
|
|
}
|
|
discard(forever: true) // expected-note {{consumed here}}
|
|
} // expected-note {{consumed again here}}
|
|
|
|
__consuming func discard(forever: Bool) { // expected-error {{'self' consumed in a loop}}
|
|
while forever {
|
|
discard self // expected-note {{consumed here}}
|
|
}
|
|
}
|
|
|
|
__consuming func inspect() { // expected-error {{'self' consumed more than once}}
|
|
switch consume self { // expected-note {{consumed here}}
|
|
// TODO: case patterns with shared block rdar://125188955
|
|
/*
|
|
case .green, .yellow, .red:
|
|
discard self // e/xpected-note {{consumed again here}}
|
|
*/
|
|
case .green:
|
|
discard self
|
|
case .yellow:
|
|
discard self
|
|
case .red:
|
|
discard self // expected-note {{consumed again here}}
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
deinit {}
|
|
|
|
}
|