Is using `withoutActuallyEscaping` within the context of a `TaskGroup` valid?

The proposal that introduced TaskGroups says:

Tasks added to the group by group.addTask() will automatically be awaited on
when the scope exits. If the group exits by throwing, all added tasks will
be cancelled and their results discarded.

So it's true that the functions don't escape the scope of the task group. However, that still counts as escaping the scope of the call to addTask, so they have to be @escaping. It would be nice to recognize that uses of enclosing non-escaping values like Philipp's example are okay (which they are — this use of withoutActuallyEscaping is fine), but currently this would require a special case in the compiler. I would hope that the upcoming generalized support for ~Escaping types will eventually allow this to be expressed directly in the language.

14 Likes