Skip to content

False unused import with -Wunused:imports #19912

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

Closed
joan38 opened this issue Mar 10, 2024 · 3 comments
Closed

False unused import with -Wunused:imports #19912

joan38 opened this issue Mar 10, 2024 · 3 comments
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@joan38
Copy link
Contributor

joan38 commented Mar 10, 2024

import cats.derived.auto.semigroup.given is reported used but if removed it was actually used.
import cats.derived.auto.semigroup.given Semigroup[?] same issue.
import cats.derived.auto.semigroup.given_Semigroup_A works fine.

Identified in kittens 3.3.0 but works with kittens 3.2.0 typelevel/kittens#655
I believe this is related to the transparent implementation for givens.

Compiler version

Reproducable in 3.3.3 and 3.4.0

Minimized code

https://scastie.scala-lang.org/Po0uhQLgSjyzEdnffZLi1g

@joan38 joan38 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 10, 2024
@Gedochao Gedochao 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 Mar 12, 2024
@Gedochao
Copy link
Contributor

Looks similar to #18564 and #19657
@szymon-rd is this a duplicate?

@som-snytt
Copy link
Contributor

The PR improves how derived and inline are handled, but without a minimization, I probably won't get to testing this.

scala-cli doesn't honor -Ylog-classpath FSR.

//> using dep org.typelevel::kittens:3.4.0
//> using options -Wunused:imports
//> using options -Xmax-inlines:64
//> abusing options "-Vprint:typer,inlining"
//> using options -color:never
//> using options -Yplain-printer
//> using options -verbose
//> using options -Ylog-classpath
//> using scala 3.6.2

import cats.Monoid
import cats.Semigroup
import cats.derived.auto.monoid.given//_Monoid_A
import cats.derived.auto.semigroup.given//_Semigroup_A
import cats.syntax.all.*

case class Rebuffers(
    total: Rebuffers.Metrics,
    network: Rebuffers.Stats,
    media: Rebuffers.Stats,
    network_media_overlap: Rebuffers.Stats,
    timedtext: Rebuffers.Stats
)

object Rebuffers:
  given Semigroup[Rebuffers] with
    def combine(x: Rebuffers, y: Rebuffers): Rebuffers = Rebuffers(
      total = x.total.combine(y.total),
      network = x.network.combine(y.network),
      media = x.media.combine(y.media),
      network_media_overlap = x.network_media_overlap.combine(y.network_media_overlap),
      timedtext = x.timedtext.combine(y.timedtext)
    )

  case class Metrics(count: Int, duration_ms: Long)
  case class Stats(total: Metrics, segment: EarlyLate, session: EarlyLate)
  case class EarlyLate(early: Metrics, late: Metrics)

@main def test() = println:
  val rebuffers: Rebuffers = Monoid[Rebuffers].empty
  rebuffers.combine(rebuffers)

@som-snytt
Copy link
Contributor

Actually it "just worked" with local compiler.

//> using scala 3.6.4-RC1-bin-SNAPSHOT
➜  snips scala-cli compile --server=false i19912.scala
-- [E205] Potential Issue Warning: /home/amarki/snips/i19912.scala:32:25 -------
 32 |      network = x.network.combine(y.network),
    |                         ^
    |Given search preference for cats.kernel.Semigroup[Rebuffers.Metrics] between alternatives
    |  (cats.derived.auto.monoid.given_Monoid_A :
    |  [A]
    |    (using evidence$1: scala.util.NotGiven[cats.kernel.Monoid[A]]):
    |      cats.kernel.Monoid[A]
    |)
    |and
    |  (cats.derived.auto.semigroup.given_Semigroup_A :
    |  [A]
    |    (using evidence$1: scala.util.NotGiven[cats.kernel.Semigroup[A]]):
    |      cats.kernel.Semigroup[A]
    |)
    |will change in the future release.
    |Current choice        : the first alternative
    |Choice from Scala 3.7 : the second alternative
    |
    |Suppress this warning by choosing -source 3.5, -source 3.7, or
    |by using @annotation.nowarn("id=205")
    |---------------------------------------------------------------------------
    |Inline stack trace
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from Derived.scala:37
     ---------------------------------------------------------------------------
1 warning found

Closing this ticket as duplicate. I would add a minimized test if one comes to light.

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 itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants