Files
swift-mirror/test/Sema/discard_resilient_inlinable.swift
Joe Groff 6f2811110d Sema: discard self should not be allowed in inlinable methods of non-frozen types.
`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.
2025-10-17 16:14:58 -07:00

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
}
}