Skip to content
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

-Wunused:imports falsely reports imported givens (for derivation) #18564

Open
MartinHH opened this issue Sep 17, 2023 · 0 comments
Open

-Wunused:imports falsely reports imported givens (for derivation) #18564

MartinHH opened this issue Sep 17, 2023 · 0 comments
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@MartinHH
Copy link

Compiler version

3.3.1

Minimized code

//> using scala "3.3.1"
//> using option "-Wunused:imports"

import scala.compiletime.*
import scala.deriving.*

trait Foo

trait HasFoo[A]:
  /** true if A contains a Foo */
  val hasFoo: Boolean

// given instances that need to be imported to be in scope
object HasFooInstances:
  given defaultHasFoo[A]: HasFoo[A] with
    val hasFoo: Boolean = false
  given HasFoo[Foo] with
    val hasFoo: Boolean = true

object HasFooDeriving:

  inline private def tupleHasFoo[T <: Tuple]: Boolean =
    inline erasedValue[T] match
      case _: EmptyTuple =>
        false
      case _: (t *: ts) =>
        summonInline[HasFoo[t]].hasFoo || tupleHasFoo[ts]
  
  inline def deriveHasFoo[T](using p: Mirror.ProductOf[T]): HasFoo[T] =
    // falsely reported as unused even though it has influence on this code
    import HasFooInstances.given
    val pHasFoo = tupleHasFoo[p.MirroredElemTypes]
    new HasFoo[T]:
      val hasFoo: Boolean = pHasFoo

Output

[warn] ./HasFoo.scala:31:28
[warn] unused import
[warn]     import HasFooInstances.given
[warn]                            ^^^^^

Note:

  1. No warning is emitted if deriveHasFoo is called in the same file
  2. A warning still is emitted if deriveHasFoo is called in a different file

Expectation

No warning is emitted.

@MartinHH MartinHH added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 17, 2023
@mbovel mbovel 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 Sep 18, 2023
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