Skip to content

Commit 62bc51b

Browse files
committed
[cxx-interop] Look up NSNotificationName in C++ language mode properly
This change makes sure that `NSNotification.Name.NEVPNStatusDidChange` is imported correctly when C++ interop is enabled. `importer::findSwiftNewtype` is called while writing Clang modules, at a point when the translation-unit scope does not exist (`clangSema.TUScope` is `nullptr`). That prevents the Clang lookup from discovering `NSNotificationName` declaration. Instead of trying to pass a translation-unit scope to Clang, let's use qualified name lookup which does not require a scope. rdar://112199372 (cherry picked from commit e956e8a)
1 parent b3ea3af commit 62bc51b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

lib/ClangImporter/ClangAdapter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ clang::TypedefNameDecl *importer::findSwiftNewtype(const clang::NamedDecl *decl,
555555
clang::LookupResult lookupResult(clangSema, notificationName,
556556
clang::SourceLocation(),
557557
clang::Sema::LookupOrdinaryName);
558-
if (!clangSema.LookupName(lookupResult, clangSema.TUScope))
558+
if (!clangSema.LookupQualifiedName(
559+
lookupResult,
560+
/*LookupCtx*/ clangSema.getASTContext().getTranslationUnitDecl()))
559561
return nullptr;
560562
auto nsDecl = lookupResult.getAsSingle<clang::TypedefNameDecl>();
561563
if (!nsDecl)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#import <Foundation/Foundation.h>
22

33
extern NSString * const SpaceShipNotification;
4+
extern "C" NSString * const CExternNotification;

test/Interop/Cxx/objc-correctness/nsnotification-bridging-ide-test.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
// CHECK: import Foundation
66

77
// CHECK: let SpaceShipNotification: String
8+
// CHECK: let CExternNotification: String
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %S/Inputs -enable-objc-interop -enable-experimental-cxx-interop
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
import NSNotificationBridging
6+
7+
func test(_ n: NSNotification.Name) {}
8+
9+
test(NSNotification.Name.SpaceShip)
10+
test(NSNotification.Name.CExtern)

0 commit comments

Comments
 (0)