1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// RUN: %target-swift-emit-silgen -verify %s
// Yes, you read that right. This is being checked in SILGen! So we have to
// separate these tests from ones emitting errors during Sema.
class ClassyGal {}
@propertyWrapper
struct Appending<Val> {
let terminator: Val
var store: [Val] = []
var wrappedValue: [Val] {
get {
return store + [terminator]
}
set {
fatalError("mutation is the root of all bugs")
}
}
}
struct StructuredGuy: ~Copyable {
let x = ClassyGal()
// expected-note@-1 {{type 'ClassyGal' cannot be trivially destroyed}}
@Appending(terminator: ClassyGal())
var bestC: [ClassyGal]
consuming func doDiscard() { discard self }
// expected-error@-1 {{can only 'discard' type 'StructuredGuy' if it contains trivially-destroyed stored properties at this time}}
deinit {}
}
struct AppendyEnby: ~Copyable {
@Appending(terminator: 0)
var string: [Int]
// expected-note@-1 {{type 'Appending<Int>' cannot be trivially destroyed}}
consuming func doDiscard() { discard self }
// expected-error@-1 {{can only 'discard' type 'AppendyEnby' if it contains trivially-destroyed stored properties at this time}}
deinit {}
}
struct HasGeneric: ~Copyable {
var thing: Any // expected-note {{type 'Any' cannot be trivially destroyed}}
consuming func discard() { discard self }
// expected-error@-1 {{can only 'discard' type 'HasGeneric' if it contains trivially-destroyed stored properties at this time}}
deinit{}
}
struct WrappingNoncopyable: ~Copyable {
var computed: String { "mine" }
var x: AppendyEnby // expected-note{{type 'AppendyEnby' cannot be trivially destroyed}}
consuming func doDiscard() { discard self }
// expected-error@-1 {{can only 'discard' type 'WrappingNoncopyable' if it contains trivially-destroyed stored properties at this time}}
deinit {}
}
struct LazyGuy: ~Copyable {
lazy var thing: String = "asdf"
// expected-note@-1 {{type 'String?' cannot be trivially destroyed}}
consuming func doDiscard() { discard self }
// expected-error@-1 {{can only 'discard' type 'LazyGuy' if it contains trivially-destroyed stored properties at this time}}
deinit {}
}
struct BoringNoncopyable: ~Copyable {
let x = 0
let y = 0
}
struct Boring {
var x = 0
var y = 1.9
}
// FIXME: Despite not having a deinit, the noncopyable struct isn't considered trivial?
struct ContainsBoring: ~Copyable {
let z: BoringNoncopyable // expected-note {{type 'BoringNoncopyable' cannot be trivially destroyed}}
consuming func discard() { discard self }
// expected-error@-1 {{can only 'discard' type 'ContainsBoring' if it contains trivially-destroyed stored properties at this time}}
deinit {}
}
struct AllOK: ~Copyable {
var maybeDigits: Int?
var maybeFloat: Float?
let dbl: Double
var location: Boring = Boring()
var unsafePtr: UnsafePointer<Int>
consuming func doDiscard() { discard self }
deinit {}
}
struct HasGenericStored<T>: ~Copyable {
let t: T // expected-note {{type 'T' cannot be trivially destroyed}}
consuming func discard() { discard self } // expected-error {{can only 'discard' type 'HasGenericStored<T>' if it contains trivially-destroyed stored properties at this time}}
deinit{}
}
struct HasAny: ~Copyable {
var t: Any // expected-note {{type 'Any' cannot be trivially destroyed}}
consuming func discard() { discard self } // expected-error {{can only 'discard' type 'HasAny' if it contains trivially-destroyed stored properties at this time}}
deinit{}
}
|