Skip to content

🍒[cxx-interop] Look up NSNotificationName in C++ language mode properly #68279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ClangImporter/ClangAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,9 @@ clang::TypedefNameDecl *importer::findSwiftNewtype(const clang::NamedDecl *decl,
clang::LookupResult lookupResult(clangSema, notificationName,
clang::SourceLocation(),
clang::Sema::LookupOrdinaryName);
if (!clangSema.LookupName(lookupResult, clangSema.TUScope))
if (!clangSema.LookupQualifiedName(
lookupResult,
/*LookupCtx*/ clangSema.getASTContext().getTranslationUnitDecl()))
return nullptr;
auto nsDecl = lookupResult.getAsSingle<clang::TypedefNameDecl>();
if (!nsDecl)
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/objc-correctness/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module NSOptionsMangling {
header "NSOptionsMangling.h"
}

module NSNofiticationBridging {
module NSNotificationBridging {
header "nsnotification-bridging.h"
requires objc
requires cplusplus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import <Foundation/Foundation.h>

extern NSString * const SpaceShipNotification;
extern "C" NSString * const CExternNotification;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// RUN: %target-swift-ide-test -print-module -module-to-print=NSNofiticationBridging -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -enable-objc-interop | %FileCheck %s
// RUN: %target-swift-ide-test -print-module -module-to-print=NSNotificationBridging -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -enable-objc-interop | %FileCheck %s

// REQUIRES: objc_interop

// CHECK: import Foundation

// CHECK: let SpaceShipNotification: String
// CHECK: let CExternNotification: String
10 changes: 10 additions & 0 deletions test/Interop/Cxx/objc-correctness/nsnotification-typechecker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %S/Inputs -enable-objc-interop -enable-experimental-cxx-interop
// REQUIRES: objc_interop

import Foundation
import NSNotificationBridging

func test(_ n: NSNotification.Name) {}

test(NSNotification.Name.SpaceShip)
test(NSNotification.Name.CExtern)