Files
swift-mirror/test/Interop/ObjC/swiftify-import/negative.swift
Henrik G. Olsson 14c79d292c [ClangImporter] don't emit empty .method()
This updates SwiftifyImportProtocolPrinter such that it no longer emits
anything for methods without bounds or lifetime info. Previously we
would not attach the macro if no methods in the protocol contained
bounds or lifetime info. However if one of the methods did, we would
still emit `.method(signature: "func foo()", paramInfo: [])` for the
methods without bounds of lifetime info. This would result in overloads
being generated, like so:
```
@_alwaysEmitIntoClient @_disfavoredOverload public
func foo() {
  return unsafe foo()
}
```

As part of this change, SwiftifyImportPrinter is now an abstract parent
type for SwiftifyImportProtocolPrinter, and the new
SwiftifyImportFunctionPrinter. Instead of SwiftifyImportProtocolPrinter
inheriting the function printing, `printMethod` instead creates a new
SwiftifyImportFunctionPrinter each time, with a new output string. If it
output anything interesting the result is forwarded, otherwise it is
discarded.
2025-10-24 18:56:45 -07:00

98 lines
2.9 KiB
Swift

// REQUIRES: swift_feature_SafeInteropWrappers
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -I %t -enable-experimental-feature SafeInteropWrappers %t/test.swift -verify -Xcc -Wno-nullability-completeness
// RUN: env SWIFT_BACKTRACE="" %target-swift-frontend -emit-module -plugin-path %swift-plugin-dir -I %t -enable-experimental-feature SafeInteropWrappers %t/test.swift -dump-macro-expansions 2> %t/expansions.out
// RUN: %diff %t/expansions.out %t/expansions.expected
//--- test.h
#pragma once
#define __counted_by(x) __attribute__((__counted_by__(x)))
@protocol NoBounds
- (void) ignore;
@end
@protocol NoYesNo
- (void) ignore;
- (void) simple:(int)len :(int * __counted_by(len))p;
- (void) ignore2;
@end
@protocol YesNo
- (void) simple:(int)len :(int * __counted_by(len))p;
- (void) ignore;
@end
@protocol YesNoYes
- (void) simple:(int)len :(int * __counted_by(len))p;
- (void) ignore;
- (void) simple2:(int)len :(int * __counted_by(len))p;
@end
//--- expansions.expected
@__swiftmacro_So05NoYesA023_SwiftifyImportProtocolfMe_.swift
------------------------------
extension NoYesNo {
/// This is an auto-generated wrapper for safer interop
@_alwaysEmitIntoClient @_disfavoredOverload public
func simple(_ p: UnsafeMutableBufferPointer<Int32>) {
let len = Int32(exactly: p.count)!
return unsafe simple(len, p.baseAddress!)
}
}
------------------------------
@__swiftmacro_So5YesNo23_SwiftifyImportProtocolfMe_.swift
------------------------------
extension YesNo {
/// This is an auto-generated wrapper for safer interop
@_alwaysEmitIntoClient @_disfavoredOverload public
func simple(_ p: UnsafeMutableBufferPointer<Int32>) {
let len = Int32(exactly: p.count)!
return unsafe simple(len, p.baseAddress!)
}
}
------------------------------
@__swiftmacro_So05YesNoA023_SwiftifyImportProtocolfMe_.swift
------------------------------
extension YesNoYes {
/// This is an auto-generated wrapper for safer interop
@_alwaysEmitIntoClient @_disfavoredOverload public
func simple(_ p: UnsafeMutableBufferPointer<Int32>) {
let len = Int32(exactly: p.count)!
return unsafe simple(len, p.baseAddress!)
}
/// This is an auto-generated wrapper for safer interop
@_alwaysEmitIntoClient @_disfavoredOverload public
func simple2(_ p: UnsafeMutableBufferPointer<Int32>) {
let len = Int32(exactly: p.count)!
return unsafe simple2(len, p.baseAddress!)
}
}
------------------------------
//--- test.swift
import TestClang
@inlinable
public func call(p: UnsafeMutableBufferPointer<CInt>, x: NoBounds, y: NoYesNo, z: YesNo, å: YesNoYes) {
x.ignore()
y.ignore()
y.simple(p)
z.ignore()
z.simple(p)
å.ignore()
å.simple(p)
å.simple2(p)
}
//--- module.modulemap
module TestClang {
header "test.h"
export *
}