scala3
scala3 copied to clipboard
Add option enabling default warnings
Resolve #18559
fyi @som-snytt
Yeah, I already said -Xlint, but I guess divergence in options is what it is. (I think paulp removed -Wall because you never want all of them, since at least one will be noisy. If you don't have a noisy warning, then you don't have enough warnings.) (Also, not a fan of all when there is _.)
@som-snytt We already have -Xlint for private/type param shadowing, the desc is advanced warning. So we have WvalueDiscard, WNonUnitStatement, WimplausiblePatterns, WunstableInlineAccessors, Wunused, and Xlint. One idea is that it may be better to change the Xlint in the direction of Wshadow and keep all of them separate. The second thing is that given that almost all the linting is already -W, the option enabling them should start with -W. The intention is to enable all of them, but we will probably skip some in the future. Maybe the real goal is not to enable them all, but to enable the recommended set that will keep your code decent. I am open to hearing other options but I'd like them to start with -W - -Wsafe, or maybe just -W / -Warn
-Warn could be a full version of -W. If no value is provided, the default is used (-W == -W:default == -Warn == -Warn:default). For real Wall with all warnings, -Warn:all could be introduced.
The existence of -Warn as alias to -W is up for discussion. As for the -Xlint I would keep it for compact as an alias for -W, as it was present in Scala 2. I would not make it default. X in -Xlint historically stands for advanced options, usually a bit more complex, not as approachable, and sometimes unstable. Warning & linting is meant to be basic, simple, and stable.
I agree that it's strongly desirable to use -W and avoid -X. The only reason Scala 2's -Xlint is -Xlint is that the -W prefix hadn't been introduced yet at the time. If -Xlint is kept at all, I even think it should be deprecated. It's not that hard for crossbuilt projects to use different flags for the two versions. Nearly every open source project I've seen already passes different compiler flags for 2 and 3.
I don't see a need for -Warn as an alias for -W — let's not proliferate alternatives and aliases. Also I think it's peculiar naming, it reads as "W + arn", like "Wconf" is "W + conf".
-Xlint is from javac, as was -Werror. (Not that WWJD is our lodestone or polestar.)
Modulo naming, I think it's nice to have a simple "here's the recommended (safe) set of warnings that are useful but not drearily painful."
But it's also nice to be able to say, "Shut down ALL the garbage mashers." (Oh, they weren't "trash compactors"! Memory is so fickle.)
Thanks, Seth, I will start calling it arn in a pirate voice.
Edit: on stability, we never figured out how to do that. Lints are unstable and progress, which has caused problems for cross-compiling, especially before nowarn and -Wconf but also after, especially when linting nowarn itself.
Close in favor of #19843