Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

add support for -Wunused #287

Closed
pelamfi opened this issue Jun 11, 2021 · 13 comments
Closed

add support for -Wunused #287

pelamfi opened this issue Jun 11, 2021 · 13 comments

Comments

@pelamfi
Copy link

pelamfi commented Jun 11, 2021

build.sbt with

scalaVersion := "3.0.0"
scalacOptions ++= Seq("-Wunused")

Produces:

[error] bad option '-Wunused' was ignored
@bishabosha bishabosha changed the title -Wunused is not supported add support for -Wunused Jun 11, 2021
@bishabosha
Copy link
Member

this also blocks support for remove unused imports rewrites

@tanishiking
Copy link

FYI, I just started working on scalafix-rule to detect unused parameter, imports, patvars, local defs, and private fields that works consistently between Scala2 and Scala3. https://github.com/tanishiking/scalafix-unused

@SethTisue
Copy link

@som-snytt do you have a sense of how plausible it is to implement this outside of the compiler? does Scalafix have enough information to do this?

@som-snytt
Copy link

som-snytt commented Aug 12, 2021

As a use case, consider whether an import or definition was "used" during implicit search. In Scala 2, the restriction was that "only the compiler implementation knows."

There is a cost for a third-party implementation for these checks.

I think the compiler should expose API. I prefer the idea of the compiler exposes data, and third-party components provide the analysis. But at this point, there is no chance of supporting both 2 & 3 that way.

@tanishiking
Copy link

In terms of implicit search, semanticdb has Synthetics section and it contains implicit parameters and implicit conversions. Therefore we should be able to handle those checks.
(Actually, metals collects the implicit symbols from synthetics to find references and I did).
(Synthetics are not available from Scala3 at this point, but it will be available once this PR has merged).

However, yes there could be some limitations because semanticdb has definitely less information than compiler APIs. I'd like to see if scalafix/semanticdb really feasible to create a robust rule :)

@SethTisue
Copy link

perhaps this should be in dotty-feature-requests

there's an umbrella thread about linting in Scala 3 at https://contributors.scala-lang.org/t/replacement-for-xlint-in-scala3/5241

@kpodsiad
Copy link

@bishabosha what is the current status of this feature request? It would be great to be able to e.g. use Scalafix's RemoveUnused rule in Scala3.

@smarter
Copy link
Member

smarter commented Jan 28, 2022

Current status: so far, no one has stepped up to implement this feature.

@bishabosha bishabosha transferred this issue from scala/scala3 Jan 28, 2022
@som-snytt
Copy link

Taking a look now. I'm willing to entertain any preconceived notions. I haven't looked at current Scalafix yet.

Sample urgency:

-- Warning: t9440-lrytz.scala:4:8 ---------------------------------------------------------------------------------------------------------------
4 |@nowarn("cat=unused-nowarn")
  |        ^^^^^^^^^^^^^^^^^^^
  |        Invalid message filter
  |        unknown category: unused-nowarn
1 warning found

We may not be 100% cat-compatible.

@bbarker
Copy link

bbarker commented Mar 27, 2022

Hi @som-snytt , just curious if you had any further finds.

More generally, maybe someone could briefly describe the compiler phases that would be best to take a look at in implementing this feature and any other high-level suggestions. Thanks!

@som-snytt
Copy link

unused imports is at scala/scala3#14524

@hartmut27
Copy link

see lampepfl/dotty/pull/16157

@kubukoz
Copy link

kubukoz commented Feb 13, 2023

I think we can close it indeed. There are some edges to clean up but we have issues tracking that.

@smarter smarter closed this as completed Feb 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants