Treat *some* warnings as errors in Swift?

一个人想着一个人 提交于 2019-11-30 23:20:29

问题


Imagine I mark the following method deprecated in Swift:

@available(*, deprecated=1.0)
func myFunc() { 
    // ...
}

And I treat warnings as errors in Swift by setting OTHER_SWIFT_FLAGS="-warnings-as-errors".

How do I make it show these deprecation notices as warnings, while still treating the rest of the warnings as errors?


It seems like GCC had a pretty good solution to this problem:

-Werror // treat all warnings as errors
-Wno-error=<warning> // don't treat <warning> as error (e.g. -Wno-error=switch)
-Werror=<warning> // treat <warning> as error

So if this was Objective-C, I could simply use -Werror -Wno-error=deprecated-declarations and get exactly what I want.

What is the equivalent for Swift?


I tried adding -Wno-error=deprecated-declarations to the OTHER_SWIFT_FLAGS, but it seems like it's not meant for Swift, so it doesn't work.


回答1:


This isn't possible. As of Swift 4, the Swift compiler doesn't have switches to either enable/disable particular warnings or promote particular warnings to errors.

The Swift core developers expressed their reluctance to add a litany of compiler flags on several occasions on the swift-evolution mailing list. The rationale is that they want to keep a single "dialect" of Swift so that every developer works with the same language features etc.

Whether this should extend to something like particular warning flags is of course debatable, but that's the current official stance. It's definitely possible that these rules will be somewhat loosened in the future, but I wouldn't bet on it.



来源:https://stackoverflow.com/questions/39235598/treat-some-warnings-as-errors-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!