Skip to content

Commit 5376e56

Browse files
Fixed no copying IsIsolated flag when cloning subscript params
1 parent c8f1de2 commit 5376e56

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11113,16 +11113,16 @@ AccessorDecl *AccessorDecl::createParsed(
1111311113
subscriptParam->getArgumentNameLoc(),
1111411114
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
1111511115
subscriptParam->getName(), /*declContext*/ accessor);
11116-
param->setAutoClosure(subscriptParam->isAutoClosure());
1111711116

1111811117
// The cloned parameter is implicit.
1111911118
param->setImplicit();
1112011119

11121-
if (subscriptParam->isSending())
11122-
param->setSending();
11123-
11124-
if (subscriptParam->isCallerIsolated())
11125-
param->setCallerIsolated();
11120+
// TODO: Check why IsVariadic is not copied.
11121+
param->setAutoClosure(subscriptParam->isAutoClosure());
11122+
param->setIsolated(subscriptParam->isIsolated());
11123+
// TODO: Check why IsAddressable is not copied.
11124+
param->setSending(subscriptParam->isSending());
11125+
param->setCallerIsolated(subscriptParam->isCallerIsolated());
1112611126

1112711127
newParams.push_back(param);
1112811128
}

test/Concurrency/isolated_parameters.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@available(SwiftStdlib 5.1, *)
1010
actor A {
11-
func f() { } // expected-typechecker-note 5{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
11+
func f() { } // expected-typechecker-note 3{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
1212
}
1313

1414
@available(SwiftStdlib 5.1, *)
@@ -364,11 +364,8 @@ func isolatedClosures() {
364364
// expected-typechecker-warning@+2 {{cannot have more than one 'isolated' parameter; this is an error in the Swift 6 language mode}}
365365
// expected-typechecker-warning@+1 {{subscript with 'isolated' parameter cannot be 'nonisolated'; this is an error in the Swift 6 language mode}}{{3-15=}}
366366
nonisolated subscript(_ a: isolated A, _ b: isolated A) -> Int {
367-
// FIXME: wrong isolation. should be isolated to `a`.
368-
#if ALLOW_TYPECHECKER_ERRORS
369-
a.f() // expected-typechecker-error {{call to actor-isolated instance method 'f()' in a synchronous actor-isolated context}}
370-
b.f() // expected-typechecker-error {{call to actor-isolated instance method 'f()' in a synchronous actor-isolated context}}
371-
#endif
367+
a.f()
368+
b.f()
372369
return 0
373370
}
374371

@@ -591,3 +588,14 @@ public actor MyActorIsolatedParameterMerge {
591588
class ClassWithIsolatedAsyncInitializer {
592589
init(isolation: isolated (any Actor)? = #isolation) async {}
593590
}
591+
592+
// https://github.com/swiftlang/swift/issues/80992
593+
struct WritableActorKeyPath<Root: Actor, Value>: Sendable {
594+
var getter: @Sendable (isolated Root) -> Value
595+
var setter: @Sendable (isolated Root, Value) -> Void
596+
597+
subscript(_ root: isolated Root) -> Value {
598+
get { getter(root) }
599+
nonmutating set { setter(root, newValue) }
600+
}
601+
}

0 commit comments

Comments
 (0)