Skip to content

[6.1] Fix source break with invalid nonisolated lazy properties #78469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7273,8 +7273,8 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
}

if (var->getAttrs().hasAttribute<LazyAttr>()) {
diagnoseAndRemoveAttr(attr, diag::nonisolated_lazy)
.warnUntilSwiftVersionIf(attr->isImplicit(), 6);
diagnose(attr->getLocation(), diag::nonisolated_lazy)
.warnUntilSwiftVersion(6);
return;
}

Expand Down
22 changes: 12 additions & 10 deletions test/Concurrency/actor_isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -834,29 +834,31 @@ 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}}
// 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-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}}
// 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-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.
Expand Down
5 changes: 5 additions & 0 deletions test/Concurrency/actor_isolation_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}