Replacement for -Xlint in Scala3?

Following up on a conversation in scala/bug#12441, is there a selected mechanism for getting -Xlint-style warnings?

If this is being moved out of the compiler into a plugin, possibly backed by something like semanticdb, that makes sense to me, I just haven’t found any documentation about it (the compiler options lookup table just lists X for those, for instance).

Thanks for your work on dotty/scala3, looking forward to moving my projects to it.

11 Likes

There isn’t one so far, and no one has stepped up to port the Scala 2 linting warnings to Scala 3 yet. I think the first step here would be to figure out which -Xlint warnings are the most popular. Then, for each of these warnings we should ask ourselves:

  • Why isn’t it enabled by default? If it’s because the false positive rate is too high or the performance impact is too important, can we solve that?
  • Is this lint only needed because of a defect in the language? If so can we fix the language instead of adding a warning?

See also this related thread in users.scala-lang: Is there an explanation of the reasoning behind various -Xlint options? - Question - Scala Users

5 Likes

I just noticed that -Xlint:deprecation is not supported yet as an alias for -deprecation.

I don’t especially like deprecations, but -Xlint is a convenient gateway for all such “not a language thing but did you notice?”

I’ll try to PR the minimal -Xlint, perhaps after that with a mechanism for extension.

Well, having multiple different flags with the same meaning isn’t great, so I’d say if we add it back it should itself be deprecated and point to -deprecation. (Also since lints are warnings -W would be more appropriate than -X, but that’s maybe too much bikeshedding.)

1 Like

Can’t have too much bike-shedding, by definition.

-Wlint to enable linting plug-ins. -Xlint was only due to java and the pun on excellent.

Deprecate -deprecation because compiler should not be emitting deprecations, which have nothing to do with correctness.

One open ticket in this area is https://github.com/lampepfl/dotty/issues/12785, about “unused” warnings specifically (“add support for -Wunused”)

8 Likes

I’m really desperate for the “value discarding” lint to return. It’s borderline essential for productively writing apps with cats-effect/zio, because value discarding can cause the app to compile in a way that just doesn’t execute branches of code.

I’ve written exactly one toy project in scala3, in a single file, and lost multiple hours to such a bug already. Newcomers to the language really need this to be productive

9 Likes

the activity on this recently created ticket looks promising: https://github.com/lampepfl/dotty/issues/15503

2 Likes

Scala 3.3.0-RC2 has -Wunused.

It’s not perfect yet. (It took a while to get the Scala 2 implementation up to its current quality level, too.) You can help by reporting issues under this label:

5 Likes

Lots of -Wunused fixes landed in 3.3.0-RC3 and 3.3.0-RC4. If you tried it before and got too many false positives, please try again.

2 Likes