scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.84k stars 1.05k forks source link

Spurious `unused private member` warning on type with parameters used in abstract refined type #19998

Open mrdziuban opened 6 months ago

mrdziuban commented 6 months ago

Compiler version

3.3.3, 3.4.0, and the latest nightly 3.4.2-RC1-bin-20240320-0ea0eba-NIGHTLY

Minimized code

//> using scala 3.4.1
//> using options -Wunused:privates

trait Foo {
  type X[a]
}

trait Bar[X[_]] {
  private final type SelfX[a] = X[a]
  val foo: Foo { type X[a] = SelfX[a] }
}

Output

-- Error: /Users/matt/scala-unused-private-type/src/main/scala/example/Test.scala:6:21
6 |  private final type SelfX[a] = X[a]
  |                     ^^^^^
  |                     unused private member

Expectation

SelfX should not be reported as unused. Interestingly, the warning goes away if X does not have type parameters.

Gedochao commented 6 months ago

@mrdziuban I can't seem to reproduce this. Tried with Scala 3.3.3, 3.4.0, 3.4.1 and 9a5b9b4598c567c60d6d339ae28bb7fbff4080db Are you calling the compiler in a specific way? any flags?

mrdziuban commented 6 months ago

@Gedochao yes, sorry I didn't include that initially, this happens with -Wunused:privates enabled. Here's a scastie that reproduces it: https://scastie.scala-lang.org/mrdziuban/t6lzDsO7RlSHtv1ONz9KBA

Gedochao commented 6 months ago

Indeed. I added the missing option to the repro description.