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

-Xlint:unused false positive with type alias #10313

Open
durban opened this issue May 14, 2017 · 5 comments
Open

-Xlint:unused false positive with type alias #10313

durban opened this issue May 14, 2017 · 5 comments
Labels
Milestone

Comments

@durban
Copy link

durban commented May 14, 2017

With this code:

package com.example

import shapeless.record._

object Foo {

  private type X = Record.`'a -> Int`.T
  private type Y = Record.`'b -> X`.T

  val foo: Y = Record(b = Record(a = 0))
}

I get the following warning with -Xlint:unused:

[warn] .../Foo.scala:7: private type X in object Foo is never used
[warn]   private type X = Record.`'a -> Int`.T
[warn]                ^

However, type X is clearly used (if I remove it, I get a compile error).

Build options:

scalaVersion := "2.12.2"
scalacOptions += "-Xlint:unused"
libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.2"

See also #10296 and scala/scala#5876.

@som-snytt
Copy link

I don't think you can do better here than disabling the linter. Macro expansion of dynamic selections means there is no usage either before or after expansion.

The code in question might as well be an interpolated string, since all the action is inside the macro.

Is it worth disabling the linter automatically if the RHS of a definition includes any macro expansion? But some macros are benign with respect to this sort of sanity check, such as a logger.

@dragos
Copy link

dragos commented May 18, 2017

Could the macro cooperate by marking the symbol as used in some way? Unused warnings are too useful to disable altogether and many people like to run with -Xfatal-warnings.

@som-snytt
Copy link

Yes, it would be easier to track usages as done by warn-imports, on the fly. Then a macro would have the option of setting a bit somewhere.

@varming
Copy link

varming commented Jul 30, 2017

Here is a false positive of -Xlint:unused not using macros:

sealed trait Foo
object Foo {
  private type T = Foo
  case object Bar extends T
}

@som-snytt
Copy link

@varming That might be worth a separate ticket.

scala> trait X ; object X { private class Y ; case object Z extends Y }
<console>:13: error: private class Y escapes its defining scope as part of type X.Y
       trait X ; object X { private class Y ; case object Z extends Y }
                                                                    ^

scala> trait X ; object X { private class Y ; type YY = Y ; case object Z extends YY }
<console>:13: error: private class Y escapes its defining scope as part of type X.Y
       trait X ; object X { private class Y ; type YY = Y ; case object Z extends YY }
                                                        ^

scala> trait X ; object X { private class Y ; private type YY = Y ; case object Z extends YY }
defined trait X
defined object X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants