SwiftLint
SwiftLint copied to clipboard
`async_without_await` triggers on methods which are marked with `@MainActor`
trafficstars
New Issue Checklist
- [x] I've Updated SwiftLint to the latest version.
- [x] I've searched for existing GitHub issues.
Bug Description
A method which has the @MainActor annotation also has to be marked with async, otherwise it will not run on the MainActor. This does not necessarily mean, that within the method, there is a await function call.
@MainActor
func() runOnMainActor async {
print("This runs on MainActor")
}
$ swiftlint lint
Environment
- SwiftLint version (58.2)
- Xcode version (16B40)
- Installation method used ( MacOS binary )
I tried
@MainActor
func f() {
MainActor.assertIsolated("Not running on main actor")
print("Running on main actor")
}
await f()
and it worked. Removing @MainActor and adding async to f panics. If MainActor.assertIsolated passes in the first case, we can assume the code runs on the main actor even without async.
The attribute rather seems to imply async as f needs to be called with await in any case.
What lets you assume it doesn't run on the main actor? Perhaps you can provide a little more context.