scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Private types trigger false positive with -Wunused:privates #11387

Open eatkins opened 5 years ago

eatkins commented 5 years ago

The following code will generate the error "private type Alias in object Foo is never used" in scala 2.12.8:

class Foo
object Foo {
  private type Alias = Foo
  def x: Foo = new Alias
}

This issue also came up in the example provided by @varming in the discussion of https://github.com/scala/bug/issues/10313.

SethTisue commented 5 years ago

I'm an unclear on why this should be a separate ticket from #10313?

som-snytt commented 5 years ago

The other example from the other ticket:

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

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

I don't know if it's the same symptom. I see YY is unused after uncurry.

Edit: the other ticket was arguably about interaction with macros, but a better mechanism would probably address both bugs.

eatkins commented 5 years ago

I see that @som-snytt already chimed in, but it was his suggestion at the bottom of #10313 that prompted my opening this issue. I have run into the issue multiple times in sbt which has both -Xfatal-warnings and -Ywarn-unused:-private set. I'd have no problem with unifying the two issues either in #10313 itself or a new issue.