Skip to content

Commit 2ca12fd

Browse files
angela-laarhborla
authored andcommitted
test function isolation expression
(cherry picked from commit 12ff5ee)
1 parent 48e39de commit 2ca12fd

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9762,7 +9762,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
97629762
// member that extracts the isolation value.
97639763
if (auto *fn = instanceTy->getAs<FunctionType>()) {
97649764
if (fn->getIsolation().isErased() &&
9765-
memberName.getBaseIdentifier().str() == "isolation") {
9765+
memberName.isSimpleName(Context.Id_isolation)) {
97669766
result.ViableCandidates.push_back(
97679767
OverloadChoice(baseTy, OverloadChoiceKind::ExtractFunctionIsolation));
97689768
}

test/Concurrency/isolated_any.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ func extractFunctionIsolationExpr(
9393

9494
// Only `@isolated(any)` functions have `.isolation`
9595
let myActor = A()
96+
let _: (any Actor)? = myActor.actorFunction.isolation // expected-error {{value of type '@Sendable () -> ()' has no member 'isolation'}}
9697
let _: (any Actor)? = myActor.asyncActorFunction.isolation // expected-error {{value of type '@Sendable () async -> ()' has no member 'isolation'}}
98+
let _: (any Actor)? = myActor.asyncThrowsActorFunction.isolation // expected-error {{value of type '@Sendable () async throws -> ()' has no member 'isolation'}}
99+
let _: (any Actor)? = myActor.actorFunctionWithArgs.isolation // expected-error {{value of type '@Sendable (Int) async -> String' has no member 'isolation'}}
100+
97101
let _: (any Actor)? = globalNonisolatedFunction.isolation // expected-error {{value of type '@Sendable () -> ()' has no member 'isolation'}}
102+
let _: (any Actor)? = globalMainActorFunction.isolation // expected-error {{value of type '@MainActor @Sendable () -> ()' has no member 'isolation'}}
103+
}
104+
105+
func requireDotIsolation(_ fn: (any Actor)?) -> (any Actor)? { return fn }
106+
107+
func testDotIsolation() {
108+
let _ : (any Actor)? = requireDotIsolation(globalMainActorFunction.isolation) // expected-error {{value of type '@MainActor @Sendable () -> ()' has no member 'isolation'}}
109+
let _ : (any Actor)? = requireDotIsolation(globalNonisolatedFunction.isolation) // expected-error {{value of type '@Sendable () -> ()' has no member 'isolation'}}
110+
}
111+
112+
func testFunctionIsolationExpr1(_ fn: (@isolated(any) () -> Void)?) -> (any Actor)? {
113+
return fn?.isolation
114+
}
115+
116+
func testFunctionIsolationExpr2(_ fn: Optional<(@isolated(any) () -> Void)>) -> Optional<any Actor> {
117+
return fn?.isolation
118+
}
119+
120+
func testFunctionIsolationExprTuple(
121+
_ fn1: (@isolated(any) () -> Void)?,
122+
_ fn2: (@isolated(any) () -> Void)?
123+
) -> ((any Actor)?, (any Actor)?)
124+
{
125+
return (fn1?.isolation, fn2?.isolation)
98126
}

0 commit comments

Comments
 (0)