Skip to content

Commit 4d814d0

Browse files
committed
Sema: Add @cdecl @implementation type-checking test variant
Based off the test for `@_cdecl @implementation`. Split between need of the ObjC interop.
1 parent 38f88ef commit 4d814d0

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

test/decl/ext/Inputs/objc_implementation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@
231231
void CImplFunc1(int param);
232232
void CImplFunc2(int param);
233233

234+
void CImplFuncRenamed_C(int param) __attribute__((swift_name("CImplFuncRenamed_Swift(arg:)")));
235+
234236
void CImplFuncMismatch1(int param);
235237
void CImplFuncMismatch2(int param);
236238

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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

Comments
 (0)