Closure isolation capture seemingly can't see through aliases – expected or a bug?

closures can currently be isolated in two ways:

  1. via a gobal-actor-isolated type annotation
  2. via a capture of an isolated parameter

for the second case, i was a bit surprised to find that certain forms of isolated parameter capture don't appear to 'count' for the purposes of this isolation determination. e.g. this works

func test_captures(isolation: isolated any Actor) async {
  await withTaskCancellationHandler {
    isolation.assertIsolated() // ✅ - isolation captured from outer scope
  } onCancel: {}
}

but this surprisingly does not:

func test_captures(isolation: isolated any Actor) async {
  await withTaskCancellationHandler { [isolation] in
    isolation.assertIsolated() // 🛑 - isolation aliased via capture list entry
  } onCancel: {}
}

is this behavior expected?

3 Likes