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

Private implicit value class causes a false positive on -Ywarn-unused #9961

Closed
scabug opened this issue Oct 14, 2016 · 3 comments
Closed

Private implicit value class causes a false positive on -Ywarn-unused #9961

scabug opened this issue Oct 14, 2016 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Oct 14, 2016

A private extension method value class triggers unused warning:

final class Foo {
  import Foo._

  def f(x: Int): Int = x.frob
}

object Foo {
  private implicit class Frobnicator(val i: Int) extends AnyVal {
    def frob: Int = i + 1729
  }
}
> scalac -Ywarn-unused -Xprint:typer Foo.scala
Foo.scala:8: warning: private object in object Foo is never used
  private implicit class Frobnicator(val i: Int) extends AnyVal {
                         ^
[[syntax trees at end of                     typer]] // Foo.scala
package <empty> {
  final class Foo extends scala.AnyRef {
    def <init>(): Foo = {
      Foo.super.<init>();
      ()
    };
    import Foo._;
    def f(x: Int): Int = Foo.Frobnicator(x).frob
  };
  object Foo extends scala.AnyRef {
    def <init>(): Foo.type = {
      Foo.super.<init>();
      ()
    };
    final implicit private class Frobnicator extends scala.AnyVal {
      <paramaccessor> private[this] val i: Int = _;
      <stable> <accessor> <paramaccessor> def i: Int = Frobnicator.this.i;
      def <init>(i: Int): Foo.Frobnicator = {
        Frobnicator.super.<init>();
        ()
      };
      def frob: Int = Frobnicator.this.i.+(1729);
      override <synthetic> def hashCode(): Int = Frobnicator.this.i.hashCode();
      override <synthetic> def equals(x$1: Any): Boolean = x$1 match {
  case (_: Foo.Frobnicator) => true
  case _ => false
}.&&({
        <synthetic> val Frobnicator$1: Foo.Frobnicator = x$1.asInstanceOf[Foo.Frobnicator];
        Frobnicator.this.i.==(Frobnicator$1.i)
      })
    };
    <synthetic> private object Frobnicator extends AnyRef {  // *** this triggers the unused warning
      def <init>(): Foo.Frobnicator.type = {
        Frobnicator.super.<init>();
        ()
      }
    };
    implicit <synthetic> private def Frobnicator(i: Int): Foo.Frobnicator = new Frobnicator(i)
  }
}

one warning found
@scabug
Copy link
Author

scabug commented Oct 14, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9961?orig=1
Reporter: @liff
Affected Versions: 2.11.8, 2.12.0-RC2
See #8040

@scabug
Copy link
Author

scabug commented Oct 14, 2016

@som-snytt said:
Already fixed in scala/scala#5402

apm@mara:~/clones/review/emergent$ scalacm -Ywarn-unused -Ystop-after:refcheck badwarn.scala
badwarn.scala:9: warning: private object in object Foo is never used
  private implicit class Frobnicator(val i: Int) extends AnyVal {
                         ^
one warning found
apm@mara:~/clones/review/emergent$ ./build/pack/bin/scalac -Ywarn-unused -Ystop-after:refcheck badwarn.scala
apm@mara:~/clones/review/emergent$

@som-snytt
Copy link

Fixed.

$ scala -Ywarn-unused
Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_111).
Type in expressions for evaluation. Or try :help.

scala> :pa
// Entering paste mode (ctrl-D to finish)

final class Foo {
  import Foo._

  def f(x: Int): Int = x.frob
}

object Foo {
  private implicit class Frobnicator(val i: Int) extends AnyVal {
    def frob: Int = i + 1729
  }
}

// Exiting paste mode, now interpreting.

defined class Foo
defined object Foo

scala> 

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

No branches or pull requests

2 participants