addTeardownBlock completion assigned to the @MainActor

Hi all,

I’m midway through a Swift 6 migration and have been migrating some unit test files recently and have been struggling a bit with whather to use MainActor in unit tests as a means to isolate certain bits of code under tests, when the code under test wouldn’t necessarily be isolated under MainActor normally in production.

Up until now, I figured this is fine in the context of a “pure” unit test since ideally you’re just testing discrete bits of business logic, and where it runs in the context of a unit test probably doesn’t matter.

However I came across this case where we’re using addTeardownBlock from XCTestCase to track memory leaks in classes that are being tested.

The heart of the issue seems that not only is AnyObject not Sendable, but also that addTeardownBlock's block is supposed to run on MainActor.

Definition according to the documentation:
@preconcurrencyfunc addTeardownBlock(_ block: @escaping @MainActor () throws -> Void)

The approach I want to take here is to just isolate the places where this is called to MainActor as a work around, but this brings me to my actual question, which is:
Why is block on addTeardownBlock isolated to the MainActor in the first place?

Thank you for sharing your thoughts and confirmation. I appreciate it!