I don't think this has anything to do with @MainActor or dictionaries, but rather you cannot capture mutable variables in sendable/escaping closures. The trailing closure of Task.detached is sendable, and self is mutable since it is a mutating method.
If this kind of code were allowed it would mean value types could be mutated from outside lexical scopes, and that would not be what is expected from value types. Even in a pre-concurrency Swift this kind of code was not allowed:
Ah yes, I distilled my real-world case too far. In my real case it definitely works - not just compiles but works at runtime just fine - but it's a SwiftUI View and the variable in question is @State.
Equivalently, change Example to a class.
Assuming the compiler error were correct (and that updateValue(:forKey:) didn't exist), what would be the alternative way to do this?
I'm also confused as to why it thinks the Dictionary subscript is an async function call. As far as I can tell, it is not.
The problem occurs for subscripting on all standard collections, as far as I can tell.