Skip to content

Unused warning for NotGiven is not useful #22969

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

Open
eejbyfeldt opened this issue Apr 11, 2025 · 2 comments · May be fixed by #22985
Open

Unused warning for NotGiven is not useful #22969

eejbyfeldt opened this issue Apr 11, 2025 · 2 comments · May be fixed by #22985
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@eejbyfeldt
Copy link

Compiler version

3.7.0-RC1

Minimized example

import scala.util.NotGiven

object Test {
  def f[T](a: Int)(using NotGiven[T <:< Int]) = a + 2
}

Output Error/Warning message

-- [E198] Unused Symbol Warning: unused_notgiven.scala:4:25 ----------------------------------
4 |  def f[T](a: Int)(using NotGiven[T <:< Int]) = a + 2
  |                         ^
  |                         unused implicit parameter
1 warning found

Why this Error/Warning was not helpful

The unused warning is not useful as NotGiven is just used for evidence and not expected to be used explicitly.

Suggested improvement

It could be made more helpful if no warning was produced. I belive NotGiven could be excluded here

case dd.DummyImplicitClass | dd.SubTypeClass | dd.SameTypeClass => true
with the same motivation as <:< and =:=.

@eejbyfeldt eejbyfeldt added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 11, 2025
@odersky
Copy link
Contributor

odersky commented Apr 11, 2025

How about other implicits that are only used for type evidence? Things like CanEqual, CanThrow, <:<, =:= ? It seems the unused warning should be disabled for these as well. But how do you tell that? It's impossible to be precise.

Also, what about implicit parameters that are unused in a given method but still need to be present since we foresee an override that would use them?

@som-snytt
Copy link
Contributor

Workaround is

def f[T](@unused a: Int)(using @unused x: NotGiven[T <:< Int]) = println()

or turn on

-Wunused:explicits

but not

-Wunused:implicits

Scala 3 does not parse -Wunused:-implicits to mean "turn off".

CanEqual is already excluded; it excludes context bounds that are "marker" traits, so probably it should exclude any implicit param that is a marker trait.

Also it should dealias more for these checks.

@som-snytt som-snytt self-assigned this Apr 11, 2025
@som-snytt som-snytt added area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants