scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Type test for local class cannot be checked at runtime in 3.2.1-RC1

Open WojciechMazur opened this issue 2 years ago • 1 comments

Regression reproduced based on Open CB #4730 found in fd4s/vulcan Part of the #15949 regression tracker

I'm not sure if it's a regression or an improvement. Code, where the error was reported, has not changed recently, so probably these warnings should be checked

Compiler version

Produces warning in 3.2.1-RC1 No warnings in 3.2.0

Minimized code

//> using options "-Xfatal-warnings"

val _ = locally{
  sealed abstract class PosInt(val value: Int) {
    override def equals(any: Any): Boolean = any.isInstanceOf[PosInt]
  }
}

Output

Compiling project (Scala 3.2.1-RC1, JVM)
[error] ./test.scala:5:46: the type test for PosInt cannot be checked at runtime
[error]     override def equals(any: Any): Boolean = any.isInstanceOf[PosInt]
[error]    

Expectation

Should compile

WojciechMazur avatar Sep 06 '22 14:09 WojciechMazur

I think that's related to a change that @dwijnand made. I believe the warning is correct in this case. But it would be nice if there was a reason given, i.e.

./test.scala:5:46: the type test for PosInt cannot be checked at runtime because PosInt is a local class`.

odersky avatar Sep 07 '22 10:09 odersky