Skip to content

Commit 042af8e

Browse files
committed
Stub out basic tests for future extensions
We eventually want to be able to implement functions imported as globals or members in Swift, but we’re not there yet. Add some basic tests to make sure we get reasonable diagnostics for them.
1 parent ce30592 commit 042af8e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test/decl/ext/Inputs/objc_implementation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ _Nonnull id CImplFuncMismatch6a(int param);
192192
void CImplFuncNameMismatch1(int param);
193193
void CImplFuncNameMismatch2(int param);
194194

195+
int CImplGetComputedGlobal1(void) __attribute__((swift_name("getter:cImplComputedGlobal1()")));
196+
void CImplSetComputedGlobal1(int param) __attribute__((swift_name("setter:cImplComputedGlobal1(newValue:)")));
197+
198+
typedef struct CImplStruct {} CImplStruct;
199+
200+
void CImplStructStaticFunc1(int param) __attribute__((swift_name("CImplStruct.staticFunc1(_:)")));
201+
195202
struct ObjCStruct {
196203
int foo;
197204
};

test/decl/ext/objc_implementation.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ protocol EmptySwiftProto {}
464464
// expected-error@-1 {{'@_objcImplementation' cannot be used to implement generic class 'ObjCImplGenericClass'}}
465465
}
466466

467+
//
468+
// @_cdecl for global functions
469+
//
470+
467471
@_objcImplementation @_cdecl("CImplFunc1")
468472
func CImplFunc1(_: Int32) {
469473
// OK
@@ -542,6 +546,38 @@ func CImplFuncNameMismatch2(_: Int32) {
542546
// FIXME: Improve diagnostic for a partial match.
543547
}
544548

549+
//
550+
// TODO: @_cdecl for global functions imported as computed vars
551+
//
552+
var cImplComputedGlobal1: Int32 {
553+
@_objcImplementation @_cdecl("CImplGetComputedGlobal1")
554+
get {
555+
// FIXME: Lookup for vars isn't working yet
556+
// 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}}
557+
return 0
558+
}
559+
560+
@_objcImplementation @_cdecl("CImplSetComputedGlobal1")
561+
set {
562+
// FIXME: Lookup for vars isn't working yet
563+
// 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}}
564+
print(newValue)
565+
}
566+
}
567+
568+
//
569+
// TODO: @_cdecl for import-as-member functions
570+
//
571+
extension CImplStruct {
572+
@_objcImplementation @_cdecl("CImplStructStaticFunc1")
573+
static func staticFunc1(_: Int32) {
574+
// FIXME: Add underlying support for this
575+
// expected-error@-3 {{@_cdecl can only be applied to global functions}}
576+
// FIXME: Lookup in an enclosing type is not working yet
577+
// 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}}
578+
}
579+
}
580+
545581
func usesAreNotAmbiguous(obj: ObjCClass) {
546582
obj.method(fromHeader1: 1)
547583
obj.method(fromHeader2: 2)

0 commit comments

Comments
 (0)