File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-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: -disable-availability-checking \
9
+ // RUN: -module-name main -I %t -verify
10
+
11
+ // REQUIRES: objc_interop
12
+ // REQUIRES: concurrency
13
+
14
+ //--- Test.h
15
+ #define SWIFT_MAIN_ACTOR __attribute__( ( swift_attr ( " @MainActor " ) ) )
16
+
17
+ #pragma clang assume_nonnull begin
18
+
19
+ @import Foundation;
20
+
21
+ SWIFT_MAIN_ACTOR
22
+ @interface Test : NSObject
23
+ @end
24
+
25
+ extern NSNotificationName const TestDidTrigger __attribute__( ( swift_name ( " Test.didTrigger " ) ) ) ;
26
+
27
+ SWIFT_MAIN_ACTOR
28
+ extern NSNotificationName const TestIsolatedTrigger __attribute__( ( swift_name ( " Test.isolatedTrigger " ) ) ) ;
29
+
30
+ #pragma clang assume_nonnull end
31
+
32
+ //--- main.swift
33
+
34
+ func testAsync( ) async {
35
+ print ( Test . didTrigger) // Ok (property is nonisolated)
36
+ print ( Test . isolatedTrigger)
37
+ // expected-warning@-1 {{expression is 'async' but is not marked with 'await'; this is an error in Swift 6}}
38
+ // expected-note@-2 {{property access is 'async'}}
39
+ }
40
+
41
+ @MainActor
42
+ func testMainActor( ) {
43
+ print ( Test . didTrigger) // Ok
44
+ print ( Test . isolatedTrigger) // Ok
45
+ }
You can’t perform that action at this time.
0 commit comments