Skip to content

Commit 65261ff

Browse files
Fixed no copying IsIsolated flag when cloning subscript params
1 parent f7bf701 commit 65261ff

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
@@ -11105,16 +11105,16 @@ AccessorDecl *AccessorDecl::createParsed(
1110511105
subscriptParam->getArgumentNameLoc(),
1110611106
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
1110711107
subscriptParam->getName(), /*declContext*/ accessor);
11108-
param->setAutoClosure(subscriptParam->isAutoClosure());
1110911108

1111011109
// The cloned parameter is implicit.
1111111110
param->setImplicit();
1111211111

11113-
if (subscriptParam->isSending())
11114-
param->setSending();
11115-
11116-
if (subscriptParam->isCallerIsolated())
11117-
param->setCallerIsolated();
11112+
// TODO: Check why IsVariadic is not copied.
11113+
param->setAutoClosure(subscriptParam->isAutoClosure());
11114+
param->setIsolated(subscriptParam->isIsolated());
11115+
// TODO: Check why IsAddressable is not copied.
11116+
param->setSending(subscriptParam->isSending());
11117+
param->setCallerIsolated(subscriptParam->isCallerIsolated());
1111811118

1111911119
newParams.push_back(param);
1112011120
}

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)