From 3f5f335458631e88dc761c4b7549c737c3535f50 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 18 Nov 2024 17:24:20 -0500 Subject: [PATCH 1/2] Sema: Downgrade nonisolated lazy error to warning until -swift-version 6 Fixes rdar://139238003. --- lib/Sema/TypeCheckAttr.cpp | 2 +- test/Concurrency/actor_isolation.swift | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index f14bf3b3af524..7c43cdd0427dc 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -7274,7 +7274,7 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) { if (var->getAttrs().hasAttribute()) { diagnoseAndRemoveAttr(attr, diag::nonisolated_lazy) - .warnUntilSwiftVersionIf(attr->isImplicit(), 6); + .warnUntilSwiftVersion(6); return; } diff --git a/test/Concurrency/actor_isolation.swift b/test/Concurrency/actor_isolation.swift index a0b39d309ab50..64e525b17826c 100644 --- a/test/Concurrency/actor_isolation.swift +++ b/test/Concurrency/actor_isolation.swift @@ -834,29 +834,29 @@ actor LazyActor { lazy var l25: Int = { [unowned self] in self.l }() nonisolated lazy var l31: Int = { v }() - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l32: Int = v - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} nonisolated lazy var l33: Int = { self.v }() - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l34: Int = self.v - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} nonisolated lazy var l35: Int = { [unowned self] in self.v }() - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l41: Int = { l }() - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} nonisolated lazy var l42: Int = l - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} nonisolated lazy var l43: Int = { self.l }() - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} nonisolated lazy var l44: Int = self.l - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} nonisolated lazy var l45: Int = { [unowned self] in self.l }() - // expected-error@-1 {{'nonisolated' is not supported on lazy properties}} + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} } // Infer global actors from context only for instance members. From 27febe2eb8dc99fd7a75c0604b08c8f271aa10e0 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 7 Jan 2025 13:21:43 -0500 Subject: [PATCH 2/2] Sema: Don't remove nonisolated attribute when we diagnose it as invalid on 'lazy' Otherwise, we'll in turn complain if the nonisolated lazy property was @objc. This is also invalid, but the goal here is to avoid the source break until -swift-version 6. Fixes rdar://141967932. --- lib/Sema/TypeCheckAttr.cpp | 2 +- test/Concurrency/actor_isolation.swift | 2 ++ test/Concurrency/actor_isolation_objc.swift | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 7c43cdd0427dc..5a1833056bead 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -7273,7 +7273,7 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) { } if (var->getAttrs().hasAttribute()) { - diagnoseAndRemoveAttr(attr, diag::nonisolated_lazy) + diagnose(attr->getLocation(), diag::nonisolated_lazy) .warnUntilSwiftVersion(6); return; } diff --git a/test/Concurrency/actor_isolation.swift b/test/Concurrency/actor_isolation.swift index 64e525b17826c..95840ad87796f 100644 --- a/test/Concurrency/actor_isolation.swift +++ b/test/Concurrency/actor_isolation.swift @@ -838,11 +838,13 @@ actor LazyActor { // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l32: Int = v // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} + // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l33: Int = { self.v }() // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l34: Int = self.v // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} + // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} nonisolated lazy var l35: Int = { [unowned self] in self.v }() // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} // expected-warning@-2 {{actor-isolated default value in a nonisolated context; this is an error in the Swift 6 language mode}} diff --git a/test/Concurrency/actor_isolation_objc.swift b/test/Concurrency/actor_isolation_objc.swift index b98a1b5975f17..2d2503bce1aab 100644 --- a/test/Concurrency/actor_isolation_objc.swift +++ b/test/Concurrency/actor_isolation_objc.swift @@ -64,3 +64,8 @@ actor Dril: NSObject { // makes sure the synthesized init's delegation kind is determined correctly. actor Pumpkin: NSObject {} + +actor Bad { + @objc nonisolated lazy var invalid = 0 + // expected-warning@-1 {{'nonisolated' is not supported on lazy properties; this is an error in the Swift 6 language mode}} +}