Skip to content

Commit e4af21f

Browse files
committed
[cxx-interop] Fix source compatibility for NSEvent.SpecialKey.upArrow.rawValue
AppKit renames some of its C constants via API Notes, e.g. `NSUpArrowFunctionKey` is renamed into `NSEvent.SpecialKey.upArrow.rawValue`. In this example, `NSEvent` is an existing type, but `SpecialKey` is not, so the Swift compiler synthesizes an empty type named `SpecialKey`. The logic that was added to support import-as-member for namespaces did not account for this: it assumed that if a nested type wasn't found, then the name must be invalid. rdar://154783494
1 parent ab54e00 commit e4af21f

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,11 @@ SwiftLookupTable::resolveContext(StringRef unresolvedName) {
359359

360360
// If we could not resolve this component of the qualified name, bail.
361361
if (!entryFound)
362-
return nullptr;
362+
break;
363363
}
364+
365+
if (!parentContext)
366+
return nullptr;
364367

365368
return parentContext.getAsDeclContext()
366369
? cast<clang::NamedDecl>(parentContext.getAsDeclContext())

test/Interop/Cxx/namespace/import-as-member-typechecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ func takesDeepNestedStruct(_ s: MyNS.MyDeepNS.DeepNestedStruct) {
2121
}
2222

2323
MyNS.method() // expected-error {{type 'MyNS' has no member 'method'}}
24-
MyNS.nestedMethod() // expected-error {{type 'MyNS' has no member 'nestedMethod'}}
24+
MyNS.nestedMethod() // expected-error {{type of expression is ambiguous without a type annotation}}

test/Interop/Cxx/objc-correctness/appkit-uikit.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -cxx-interoperability-mode=default %s
2+
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -cxx-interoperability-mode=default %s -swift-version 6
23

34
// REQUIRES: objc_interop
45
// REQUIRES: VENDOR=apple
@@ -9,6 +10,8 @@ import AppKit
910

1011
var _: AttributeScopes.AppKitAttributes.UnderlineStyleAttribute! = nil
1112

13+
var _ = NSEvent.SpecialKey.upArrow.rawValue
14+
1215
#elseif canImport(UIKit)
1316
import UIKit
1417

0 commit comments

Comments
 (0)