File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -7956,6 +7956,7 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
7956
7956
if (!ClangDecl)
7957
7957
return ;
7958
7958
7959
+
7959
7960
// Subscripts are special-cased since there isn't a 1:1 mapping
7960
7961
// from its accessor(s) to the subscript declaration.
7961
7962
if (isa<SubscriptDecl>(MappedDecl))
@@ -8138,6 +8139,23 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8138
8139
/* isUnchecked=*/ true );
8139
8140
}
8140
8141
}
8142
+
8143
+ // Special handling of `NSNotificationName` static immutable properties.
8144
+ //
8145
+ // These constants could be used with observer APIs from a different isolation
8146
+ // context, so it's more convenient to import them as `nonisolated` unless
8147
+ // they are explicitly isolated to a MainActor.
8148
+ if (!seenMainActorAttr) {
8149
+ auto *DC = MappedDecl->getDeclContext ();
8150
+ if (DC->isTypeContext () && isa<VarDecl>(MappedDecl)) {
8151
+ auto *mappedVar = cast<VarDecl>(MappedDecl);
8152
+ if (mappedVar->isStatic () && mappedVar->isLet () &&
8153
+ isNSNotificationName (cast<clang::ValueDecl>(ClangDecl)->getType ())) {
8154
+ MappedDecl->getAttrs ().add (new (SwiftContext) NonisolatedAttr (
8155
+ /* unsafe=*/ false , /* implicit=*/ true ));
8156
+ }
8157
+ }
8158
+ }
8141
8159
}
8142
8160
8143
8161
static bool isUsingMacroName (clang::SourceManager &SM,
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t/src)
2
+ // RUN: %empty-directory(%t/sdk)
3
+ // RUN: split-file %s %t/src
4
+
5
+ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck %t/src/main.swift \
6
+ // RUN: -import-objc-header %t/src/Test.h \
7
+ // RUN: -strict-concurrency=complete \
8
+ // RUN: -module-name main -I %t -verify
9
+
10
+ // REQUIRES: objc_interop
11
+ // REQUIRES: concurrency
12
+
13
+ //--- Test.h
14
+ #define SWIFT_MAIN_ACTOR __attribute__( ( swift_attr ( " @MainActor " ) ) )
15
+
16
+ #pragma clang assume_nonnull begin
17
+
18
+ @import Foundation;
19
+
20
+ SWIFT_MAIN_ACTOR
21
+ @interface Test : NSObject
22
+ @end
23
+
24
+ extern NSNotificationName const TestDidTrigger __attribute__( ( swift_name ( " Test.didTrigger " ) ) ) ;
25
+
26
+ SWIFT_MAIN_ACTOR
27
+ extern NSNotificationName const TestIsolatedTrigger __attribute__( ( swift_name ( " Test.isolatedTrigger " ) ) ) ;
28
+
29
+ #pragma clang assume_nonnull end
30
+
31
+ //--- main.swift
32
+
33
+ func testAsync( ) async {
34
+ print ( Test . didTrigger) // Ok (property is nonisolated)
35
+ print ( Test . isolatedTrigger)
36
+ // expected-warning@-1 {{expression is 'async' but is not marked with 'await'; this is an error in Swift 6}}
37
+ // expected-note@-2 {{property access is 'async'}}
38
+ }
39
+
40
+ @MainActor
41
+ func testMainActor( ) {
42
+ print ( Test . didTrigger) // Ok
43
+ print ( Test . isolatedTrigger) // Ok
44
+ }
You can’t perform that action at this time.
0 commit comments