Skip to content

Commit 6d2e87f

Browse files
authored
Merge pull request #72367 from angela-laar/dot-isolation-member-for-optionals
[Sema] `.isolation` member missing for optional function values
2 parents a5ae7b0 + 12ff5ee commit 6d2e87f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9758,9 +9758,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
97589758

97599759
// Dynamically isolated function types have a magic '.isolation'
97609760
// member that extracts the isolation value.
9761-
if (auto *fn = dyn_cast<FunctionType>(instanceTy)) {
9761+
if (auto *fn = instanceTy->getAs<FunctionType>()) {
97629762
if (fn->getIsolation().isErased() &&
9763-
memberName.getBaseIdentifier().str() == "isolation") {
9763+
memberName.isSimpleName(Context.Id_isolation)) {
97649764
result.ViableCandidates.push_back(
97659765
OverloadChoice(baseTy, OverloadChoiceKind::ExtractFunctionIsolation));
97669766
}

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)