mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
`discard self` requires knowledge of the internal layout of the type in order to clean up its fields while bypassing its public `deinit`. Inlinable code can get copied into and run from outside of the defining module, so this is impossible to implement. Fixes rdar://160815058.
70 lines
1.7 KiB
Swift
70 lines
1.7 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
public struct NotFrozen: ~Copyable {
|
|
deinit {}
|
|
|
|
public consuming func notInlinable() {
|
|
discard self
|
|
}
|
|
|
|
@inlinable
|
|
public consuming func inlinable() {
|
|
// expected-warning @+1 {{'discard' statement cannot be used in an '@inlinable' function inside of type 'NotFrozen', which is not '@frozen'}}
|
|
discard self
|
|
}
|
|
|
|
@_alwaysEmitIntoClient
|
|
public consuming func aeic() {
|
|
// expected-error @+1 {{'discard' statement cannot be used in an '@_alwaysEmitIntoClient' function inside of type 'NotFrozen', which is not '@frozen'}}
|
|
discard self
|
|
}
|
|
|
|
@_transparent
|
|
public consuming func transparent() {
|
|
// expected-error @+1 {{'discard' statement cannot be used in a '@_transparent' function inside of type 'NotFrozen', which is not '@frozen'}}
|
|
discard self
|
|
}
|
|
}
|
|
|
|
@frozen
|
|
public struct Frozen: ~Copyable {
|
|
deinit {}
|
|
|
|
public consuming func notInlinable() {
|
|
discard self
|
|
}
|
|
|
|
@inlinable
|
|
public consuming func inlinable() {
|
|
discard self
|
|
}
|
|
}
|
|
|
|
@usableFromInline
|
|
internal struct NotFrozenUFI: ~Copyable {
|
|
deinit {}
|
|
|
|
public consuming func notInlinable() {
|
|
discard self
|
|
}
|
|
|
|
@inlinable
|
|
public consuming func inlinable() {
|
|
// expected-warning @+1 {{'discard' statement cannot be used in an '@inlinable' function inside of type 'NotFrozenUFI', which is not '@frozen'}}
|
|
discard self
|
|
}
|
|
|
|
@_alwaysEmitIntoClient
|
|
public consuming func aeic() {
|
|
// expected-error @+1 {{'discard' statement cannot be used in an '@_alwaysEmitIntoClient' function inside of type 'NotFrozenUFI', which is not '@frozen'}}
|
|
discard self
|
|
}
|
|
|
|
@_transparent
|
|
public consuming func transparent() {
|
|
// expected-error @+1 {{'discard' statement cannot be used in a '@_transparent' function inside of type 'NotFrozenUFI', which is not '@frozen'}}
|
|
discard self
|
|
}
|
|
}
|
|
|