MainActor isolation does not pass to nested functions defined within a closure #73301
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
concurrency
Feature: umbrella label for concurrency language features
Description
I'm not 100% certain this is actually bug, it could be my lack of understanding how MainActor isolation is inferred. If you declare a nested function on a MainActor isolated type, but do so inside a closure, it seems that the nested function does not inherit MainActor isolation. I've attached a minimal reproducing case.
The closure passed to
UIDeferredMenuElement.uncached()
is not annotated with@MainActor
, althoughUIDeferredMenuElement
itself is.I honestly do not know if MainActor isolation carries over to this static method argument.
Note that accessing state on
ViewController
(which is MainActor isolated) from within this closure does not raise an error.Explicitly annotating the
bar()
nested function with@MainActor
resolves the compiler error.Reproduction
Expected behavior
I'm not certain, but I believe this nested function should automatically inherit
MainActor
isolation from its containing type, and thus no compiler error should be raised.Environment
Xcode 15.2 (15C500b)
Test project with deployment target of iOS 17.0
SWIFT_STRICT_CONCURRENCY=complete
Additional information
No response
The text was updated successfully, but these errors were encountered: