From e663ad0cbd74391e460353be010d5e8deff61f47 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 7 Jan 2025 13:21:43 -0500 Subject: [PATCH] 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 fff0dcb9cb2b2..326982cb37bb0 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -7449,7 +7449,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}} +}