scala / bug

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

Spurious deprecation when using type/value alias pair #13006

Closed lrytz closed 3 months ago

lrytz commented 3 months ago

On 2.13.14:

scala> @deprecated case class C(x: Int)
class C

scala> object A { type X = C; val X = C }
                           ^
       warning: class C is deprecated
object A

scala> new A.X(10) // no deprecation
val res0: C = C(10)

scala> A.X.toString // no deprecation
val res1: String = C

scala> A.X.apply(10) // spurious deprecation
           ^
       warning: class C is deprecated
val res2: C = C(10)

The warning is actually issued while performing transformCaseApply, which happens during refchecks. 2.12 doesn't warn because the compiler doesn't see through the alias and doesn't trigger the transformCaseApply optimization.

lrytz commented 3 months ago

For the record, Scala 3 already warns one line earlier...

scala> @deprecated case class C(x: Int)
// defined case class C

scala> object A { type X = C; val X = C }
1 warning found
-- Deprecation Warning: --------------------------------------------------------
1 |object A { type X = C; val X = C }
  |                    ^
  |                    class C is deprecated
// defined object A

scala> new A.X(10) // no deprecation
val res2: C = C(10)

scala> A.X.toString // spurious deprecation
1 warning found
-- Deprecation Warning: --------------------------------------------------------
1 |A.X.toString // spurious deprecation
  |^^^^^^^^^^^^
  |class C is deprecated
val res3: String = C

scala> A.X.apply(10) // spurious deprecation
1 warning found
-- Deprecation Warning: --------------------------------------------------------
1 |A.X.apply(10) // spurious deprecation
  |^^^^^^^^^
  |class C is deprecated
val res4: C = C(10)

That must be yet another feature interaction. It's not that Scala 3 generally looks through aliases to find deprecations. type Alias = DeprecatedClass; new Alias doesn't warn.