|
| 1 | +// RUN: %target-typecheck-verify-swift -target %target-stable-abi-triple \ |
| 2 | +// RUN: -import-bridging-header %S/Inputs/objc_implementation.h \ |
| 3 | +// RUN: -disable-objc-interop \ |
| 4 | +// RUN: -enable-experimental-feature CImplementation \ |
| 5 | +// RUN: -enable-experimental-feature CDecl |
| 6 | + |
| 7 | +// REQUIRES: swift_feature_CImplementation |
| 8 | +// REQUIRES: swift_feature_CDecl |
| 9 | + |
| 10 | +@implementation @cdecl |
| 11 | +func CImplFunc1(_: Int32) { |
| 12 | + // OK |
| 13 | +} |
| 14 | + |
| 15 | +@implementation @cdecl(CImplFuncRenamed_C) |
| 16 | +func CImplFuncRenamed_Swift(arg: CInt) { |
| 17 | + // OK |
| 18 | +} |
| 19 | + |
| 20 | +@implementation(BadCategory) @cdecl |
| 21 | +func CImplFunc2(_: Int32) { |
| 22 | + // expected-error@-2 {{global function 'CImplFunc2' does not belong to an Objective-C category; remove the category name from this attribute}} {{16-29=}} |
| 23 | +} |
| 24 | + |
| 25 | +@implementation @cdecl |
| 26 | +func CImplFuncMissing(_: Int32) { |
| 27 | + // expected-error@-2 {{could not find imported function 'CImplFuncMissing' matching global function 'CImplFuncMissing'; make sure your umbrella or bridging header imports the header that declares it}} |
| 28 | +} |
| 29 | + |
| 30 | +@implementation @cdecl |
| 31 | +func CImplFuncMismatch1(_: Float) { |
| 32 | + // expected-error@-1 {{global function 'CImplFuncMismatch1' of type '(Float) -> ()' does not match type '(Int32) -> Void' declared by the header}} |
| 33 | +} |
| 34 | + |
| 35 | +@implementation @cdecl |
| 36 | +func CImplFuncMismatch2(_: Int32) -> Float { |
| 37 | + // expected-error@-1 {{global function 'CImplFuncMismatch2' of type '(Int32) -> Float' does not match type '(Int32) -> Void' declared by the header}} |
| 38 | +} |
| 39 | + |
| 40 | +@implementation @cdecl(CImplFuncNameMismatch1) |
| 41 | +func mismatchedName1(_: Int32) { |
| 42 | + // expected-error@-2 {{could not find imported function 'CImplFuncNameMismatch1' matching global function 'mismatchedName1'; make sure your umbrella or bridging header imports the header that declares it}} |
| 43 | + // FIXME: Improve diagnostic for a partial match. |
| 44 | +} |
| 45 | + |
| 46 | +@implementation @cdecl(mismatchedName2) |
| 47 | +func CImplFuncNameMismatch2(_: Int32) { |
| 48 | + // expected-error@-2 {{could not find imported function 'mismatchedName2' matching global function 'CImplFuncNameMismatch2'; make sure your umbrella or bridging header imports the header that declares it}} |
| 49 | + // FIXME: Improve diagnostic for a partial match. |
| 50 | +} |
| 51 | + |
| 52 | +// |
| 53 | +// TODO: @cdecl for global functions imported as computed vars |
| 54 | +// |
| 55 | +var cImplComputedGlobal1: Int32 { |
| 56 | + @implementation @cdecl(CImplGetComputedGlobal1) |
| 57 | + get { |
| 58 | + // FIXME: Lookup for vars isn't working yet |
| 59 | + // expected-error@-3 {{could not find imported function 'CImplGetComputedGlobal1' matching getter for var 'cImplComputedGlobal1'; make sure your umbrella or bridging header imports the header that declares it}} |
| 60 | + return 0 |
| 61 | + } |
| 62 | + |
| 63 | + @implementation @cdecl(CImplSetComputedGlobal1) |
| 64 | + set { |
| 65 | + // FIXME: Lookup for vars isn't working yet |
| 66 | + // expected-error@-3 {{could not find imported function 'CImplSetComputedGlobal1' matching setter for var 'cImplComputedGlobal1'; make sure your umbrella or bridging header imports the header that declares it}} |
| 67 | + print(newValue) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// |
| 72 | +// TODO: @cdecl for import-as-member functions |
| 73 | +// |
| 74 | +extension CImplStruct { |
| 75 | + @implementation @cdecl(CImplStructStaticFunc1) |
| 76 | + static func staticFunc1(_: Int32) { |
| 77 | + // FIXME: Add underlying support for this |
| 78 | + // expected-error@-3 {{@cdecl can only be applied to global functions}} |
| 79 | + // FIXME: Lookup in an enclosing type is not working yet |
| 80 | + // expected-error@-5 {{could not find imported function 'CImplStructStaticFunc1' matching static method 'staticFunc1'; make sure your umbrella or bridging header imports the header that declares it}} |
| 81 | + } |
| 82 | +} |
0 commit comments