Files
swift-mirror/test/ModuleInterface/discard_interface.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

20 lines
745 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library -verify
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -I %t
// RUN: %FileCheck %s < %t/Library.swiftinterface
// This test makes sure that discard is emitted correctly in the interfaces.
// CHECK: @_alwaysEmitIntoClient public consuming func AEIC_discard() { discard self }
// CHECK: @inlinable public consuming func inlinable_discard() { discard self }
@frozen
public struct MoveOnlyStruct: ~Copyable {
let x = 0
@_alwaysEmitIntoClient public consuming func AEIC_discard() { discard self }
@inlinable public consuming func inlinable_discard() { discard self }
deinit {}
}