Skip to content

Nothing inferred with pattern matching and invariant type parameter #1960

Closed
@OlivierBlanvillain

Description

@OlivierBlanvillain

In the following:

case class CC2[A, B](_1: A, _2: B)

object Test {
  def main(args: Array[String]): Unit = {
    val CC2(_, CC2(a, _)) = CC2(0, CC2(1, 2))
    assert(a == 1)
  }
}

a type is inferred to Nothing which leads to a ClassCastException (it's also caught by Ycheck).

The issue might be related to name base pattern matching given that this example work as expected using Tuple2 instead of CC2.

Edit: Looks like a variance thing actually, type are inferred as expected with a covariant CC2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions