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 @@ -8138,6 +8138,23 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
8138
8138
/* isUnchecked=*/ true );
8139
8139
}
8140
8140
}
8141
+
8142
+ // Special handling of `NSNotificationName` static immutable properties.
8143
+ //
8144
+ // These constants could be used with observer APIs from a different isolation
8145
+ // context, so it's more convenient to import them as `nonisolated` unless
8146
+ // they are explicitly isolated to a MainActor.
8147
+ if (!seenMainActorAttr) {
8148
+ auto *DC = MappedDecl->getDeclContext ();
8149
+ if (DC->isTypeContext () && isa<VarDecl>(MappedDecl)) {
8150
+ auto *mappedVar = cast<VarDecl>(MappedDecl);
8151
+ if (mappedVar->isStatic () && mappedVar->isLet () &&
8152
+ isNSNotificationName (cast<clang::ValueDecl>(ClangDecl)->getType ())) {
8153
+ MappedDecl->getAttrs ().add (new (SwiftContext) NonisolatedAttr (
8154
+ /* unsafe=*/ false , /* implicit=*/ true ));
8155
+ }
8156
+ }
8157
+ }
8141
8158
}
8142
8159
8143
8160
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