Skip to content

Tuple specialisation doesn't correctly see type  #18638

Closed
@klaeufer

Description

@klaeufer

Compiler version

Welcome to Scala 3.3.1 (17.0.8.1, Java OpenJDK 64-Bit Server VM).

Minimized code

type U[H, T] = (Unit, Unit)

(((), ()): U[Int, Int]) match
  case ((), ()) => println("ok")

Output

java.lang.ClassCastException: class scala.runtime.BoxedUnit cannot be cast to class java.lang.Integer (scala.runtime.BoxedUnit is in unnamed module of loader java.net.URLClassLoader @5eefa415; java.lang.Integer is in module java.base of loader 'bootstrap')

Expectation

  • Should print "ok".
  • Should behave the same as when unannotated or annotated with result of manually applying type alias to parameters:
(((), ()): (Unit, Unit)) match
  case ((), ()) => println("ok")
ok

Additional observations

  • This problem did not occur in Scala 3.1.x, and I first observed it in Scala 3.2.0.
  • The problem seems to occur only for Tuple2 and 2-ary type aliases.
  • The problem occurs for two, not necessary equal, integer-based actual type parameters: Boolean, Char, Int, Long
  • It doesn't matter what the concrete tuple element types are, as long as at least one of them is different from the corresponding actual type parameter.
  • It doesn't make a difference if the type parameters are actually used, e.g.,
    type ListNodeF[H, T] = (H, Option[T])

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions