Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redundantInit causes "initializing from a metatype value must reference 'init' explicitly" #1672

Closed
marcelofabri opened this issue Apr 12, 2024 · 3 comments
Labels
fixed in develop bug/feature resolved in the develop branch known issue

Comments

@marcelofabri
Copy link

Given this code:

let a = Module.configuration.loggingEventBatchType.init(
   anyEvents: eventsToUpload
)

0.53.6 removes the .init, causing an error:

error: initializing from a metatype value must reference 'init' explicitly

loggingEventBatchType is defined as AnyLoggingEventBatch.Type

@nicklockwood
Copy link
Owner

There's currently not really a way for SwiftFormat to detect this case since it doesn't have access to type information. The best option for now would be to disable the rule, either globally or locally using:

// swiftformat:disable:next redundantInit
let a = Module.configuration.loggingEventBatchType.init(
   anyEvents: eventsToUpload
)

@nicklockwood nicklockwood added known issue fixed in develop bug/feature resolved in the develop branch labels Apr 13, 2024
@nicklockwood
Copy link
Owner

@marcelofabri I realized on reflection that the existing heuristic I use to avoid false positives for redundantInit ought to handle this case as well, so I've pushed a fix to develop that should solve it

@nicklockwood
Copy link
Owner

@marcelofabri fixed in 0.53.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in develop bug/feature resolved in the develop branch known issue
Projects
None yet
Development

No branches or pull requests

2 participants