Is it incorrect to use Array.forEach with strict concurrency?

This definitely seems like a bug: lazy properties of @MainActor isolated classes are already initialized on the main actor, but the compiler doesn't seem to be able to see that fact. This has the same bug (plus the fact that it thinks there's a throwing closure in here):

@MainActor
class SomeClass {
    lazy var string: Void = {
        ["one", "two"].forEach(printString) // Errors
    }()
}

@MainActor
func printString(_ input: String) {
    print("\(input)string")
}

which produces both

Call can throw, but it is not marked with 'try' and the error is not handled

and

Converting function value of type '@MainActor (String) throws -> Void' to '(String) throws -> Void' loses global actor 'MainActor'

which both seems like bugs.

5 Likes