Skip to content

Commit ce30592

Browse files
committed
Test cImpl type and name mismatches
1 parent 1612c6e commit ce30592

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,9 +3389,10 @@ class ObjCImplementationChecker {
33893389
}
33903390

33913391
static Type getMemberType(ValueDecl *decl) {
3392-
if (isa<AbstractFunctionDecl>(decl))
3393-
// Strip off the uncurried `self` parameter.
3394-
return decl->getInterfaceType()->getAs<AnyFunctionType>()->getResult();
3392+
if (auto fn = dyn_cast<AbstractFunctionDecl>(decl))
3393+
if (fn->hasImplicitSelfDecl())
3394+
// Strip off the uncurried `self` parameter.
3395+
return fn->getMethodInterfaceType();
33953396
return decl->getInterfaceType();
33963397
}
33973398

test/decl/ext/Inputs/objc_implementation.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@
179179
void CImplFunc1(int param);
180180
void CImplFunc2(int param);
181181

182+
void CImplFuncMismatch1(int param);
183+
void CImplFuncMismatch2(int param);
184+
void CImplFuncMismatch3(_Nullable id param);
185+
void CImplFuncMismatch4(_Nullable id param);
186+
void CImplFuncMismatch5(_Nonnull id param);
187+
void CImplFuncMismatch6(_Nonnull id param);
188+
_Nullable id CImplFuncMismatch3a(int param);
189+
_Nullable id CImplFuncMismatch4a(int param);
190+
_Nonnull id CImplFuncMismatch5a(int param);
191+
_Nonnull id CImplFuncMismatch6a(int param);
192+
void CImplFuncNameMismatch1(int param);
193+
void CImplFuncNameMismatch2(int param);
194+
182195
struct ObjCStruct {
183196
int foo;
184197
};

test/decl/ext/objc_implementation.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,69 @@ func CImplFuncMissing(_: Int32) {
479479
// 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}}
480480
}
481481

482+
@_objcImplementation @_cdecl("CImplFuncMismatch1")
483+
func CImplFuncMismatch1(_: Float) {
484+
// expected-warning@-1 {{global function 'CImplFuncMismatch1' of type '(Float) -> ()' does not match type '(Int32) -> Void' declared by the header}}
485+
}
486+
487+
@_objcImplementation @_cdecl("CImplFuncMismatch2")
488+
func CImplFuncMismatch2(_: Int32) -> Float {
489+
// expected-warning@-1 {{global function 'CImplFuncMismatch2' of type '(Int32) -> Float' does not match type '(Int32) -> Void' declared by the header}}
490+
}
491+
492+
@_objcImplementation @_cdecl("CImplFuncMismatch3")
493+
func CImplFuncMismatch3(_: Any?) {
494+
// OK
495+
}
496+
497+
@_objcImplementation @_cdecl("CImplFuncMismatch4")
498+
func CImplFuncMismatch4(_: Any) {
499+
// expected-warning@-1 {{global function 'CImplFuncMismatch4' of type '(Any) -> ()' does not match type '(Any?) -> Void' declared by the header}}
500+
}
501+
502+
@_objcImplementation @_cdecl("CImplFuncMismatch5")
503+
func CImplFuncMismatch5(_: Any) {
504+
// OK
505+
}
506+
507+
@_objcImplementation @_cdecl("CImplFuncMismatch6")
508+
func CImplFuncMismatch6(_: Any!) {
509+
// OK, mismatch allowed
510+
}
511+
512+
513+
@_objcImplementation @_cdecl("CImplFuncMismatch3a")
514+
func CImplFuncMismatch3a(_: Int32) -> Any? {
515+
// OK
516+
}
517+
518+
@_objcImplementation @_cdecl("CImplFuncMismatch4a")
519+
func CImplFuncMismatch4a(_: Int32) -> Any {
520+
// expected-warning@-1 {{global function 'CImplFuncMismatch4a' of type '(Int32) -> Any' does not match type '(Int32) -> Any?' declared by the header}}
521+
}
522+
523+
@_objcImplementation @_cdecl("CImplFuncMismatch5a")
524+
func CImplFuncMismatch5a(_: Int32) -> Any {
525+
// OK
526+
}
527+
528+
@_objcImplementation @_cdecl("CImplFuncMismatch6a")
529+
func CImplFuncMismatch6a(_: Int32) -> Any! {
530+
// OK, mismatch allowed
531+
}
532+
533+
@_objcImplementation @_cdecl("CImplFuncNameMismatch1")
534+
func mismatchedName1(_: Int32) {
535+
// 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}}
536+
// FIXME: Improve diagnostic for a partial match.
537+
}
538+
539+
@_objcImplementation @_cdecl("mismatchedName2")
540+
func CImplFuncNameMismatch2(_: Int32) {
541+
// 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}}
542+
// FIXME: Improve diagnostic for a partial match.
543+
}
544+
482545
func usesAreNotAmbiguous(obj: ObjCClass) {
483546
obj.method(fromHeader1: 1)
484547
obj.method(fromHeader2: 2)

0 commit comments

Comments
 (0)