Files
swift-mirror/test/Interpreter/moveonly_computed_property_in_class.swift
2024-07-23 11:05:33 -07:00

32 lines
833 B
Swift

// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all)
// RUN: %target-run-simple-swift(-O -Xfrontend -sil-verify-all)
// REQUIRES: executable_test
struct FileDescriptor: ~Copyable {
let desc: Int
var empty: Bool { return desc == Int.min }
func isEmpty() -> Bool { return empty }
}
final class Wrapper {
var val: FileDescriptor = FileDescriptor(desc: 0)
func isEmpty_bug() -> Bool {
// error: 'self.val' has consuming use that cannot
// be eliminated due to a tight exclusivity scope
return val.empty // note: consuming use here
}
func isEmpty_ok() -> Bool {
return val.isEmpty()
}
}
let w = Wrapper()
// CHECK: is not empty
print(w.isEmpty_bug() ? "is empty" : "is not empty")
w.val = FileDescriptor(desc: Int.min)
// CHECK: is empty
print(w.isEmpty_bug() ? "is empty" : "is not empty")