Skip to content

Commit 1811438

Browse files
authored
Merge pull request swiftlang#41457 from kavon/downgrade-deux
accept serialized modules with superflous global-actor annotations
2 parents 01b539e + ef72c5b commit 1811438

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4794,8 +4794,8 @@ ERROR(global_actor_on_actor_class,none,
47944794
ERROR(global_actor_on_local_variable,none,
47954795
"local variable %0 cannot have a global actor", (DeclName))
47964796
ERROR(global_actor_on_storage_of_value_type,none,
4797-
"stored property %0 within %1 cannot have a global actor",
4798-
(DeclName, DescriptiveDeclKind))
4797+
"stored property %0 within struct cannot have a global actor",
4798+
(DeclName))
47994799
ERROR(global_actor_non_unsafe_init,none,
48004800
"global actor attribute %0 argument can only be '(unsafe)'", (Type))
48014801
ERROR(global_actor_non_final_class,none,

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ GlobalActorAttributeRequest::evaluate(
323323
// Check that a global actor attribute makes sense on this kind of
324324
// declaration.
325325
auto decl = subject.get<Decl *>();
326+
327+
// no further checking required if it's from a serialized module.
328+
if (decl->getDeclContext()->getParentSourceFile() == nullptr)
329+
return result;
330+
326331
auto globalActorAttr = result->first;
327332
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
328333
// Nominal types are okay...
@@ -358,7 +363,7 @@ GlobalActorAttributeRequest::evaluate(
358363
if (isa<StructDecl>(nominal) && !isWrappedValueOfPropWrapper(var)) {
359364

360365
var->diagnose(diag::global_actor_on_storage_of_value_type,
361-
var->getName(), nominal->getDescriptiveKind())
366+
var->getName())
362367
.highlight(globalActorAttr->getRangeWithAt())
363368
.warnUntilSwiftVersion(6);
364369

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
public struct MySerializedStruct {
3+
@MainActor public var counter = 0
4+
5+
public init() {}
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -swift-version 5 -emit-module-path %t/SerializedStruct.swiftmodule -module-name SerializedStruct %S/Inputs/SerializedStruct.swift
3+
// RUN: %target-swift-frontend %s -typecheck -disable-availability-checking -swift-version 6 -I %t
4+
5+
// REQUIRES: concurrency
6+
// REQUIRES: asserts
7+
8+
// This test ensures that, when loading a Swift 5 serialized module with
9+
// a global-actor annotation that is an error in Swift 6, but only a warning
10+
// in Swift 5, then we do not reject the import as an error.
11+
12+
import SerializedStruct
13+
14+
// use it to force the right checks happen.
15+
func test() async -> Int {
16+
let x = MySerializedStruct()
17+
return await x.counter // Because the module is from Swift 5, an await is needed.
18+
}

0 commit comments

Comments
 (0)