-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:match-typesitype:bugregressionThis worked in a previous version but doesn't anymoreThis worked in a previous version but doesn't anymore
Description
Compiler version
3.6.2, 3.7.1
Minimized code
object MatchTypes {
type ConstituentPartOf[A] = A match {
case BigInt => Int
case String => Char
}
def lastPartOf[A](thing: A): ConstituentPartOf[A] = thing match {
case number: BigInt => (number % 10).toInt
case string: String => string.charAt(string.length - 1)
}
def main(args: Array[String]): Unit = {
val lastPartOfSomethingElse = lastPartOf(BigDecimal("10"))
println(lastPartOfSomethingElse)
}
}
Output
Program compiles succesfully (which it shouldn't), and throws an exception at runtime:
Exception in thread "main" scala.MatchError: 10 (of class scala.math.BigDecimal)
at MatchTypes$.lastPartOf(MatchTypes.scala:10)
at MatchTypes$.main(MatchTypes.scala:14)
at MatchTypes.main(MatchTypes.scala)
Expectation
It should throw a compilation error as it does in scala 3.3.6

Metadata
Metadata
Assignees
Labels
area:match-typesitype:bugregressionThis worked in a previous version but doesn't anymoreThis worked in a previous version but doesn't anymore