Skip to content

MatchType does not reduce for GADT aliases #6687

Closed
@odersky

Description

@odersky
  type T[X] = X match {
    case String => Int
    case Int => String
  }

  class Box[X](x: X)

  def f[X <: String | Int](x: X): T[X] = Box(x) match {
    case x: Box[Int] => ""        // <-- error
    case x: Box[String] => 1
  }

This gives:

10 |    case x: Box[Int] => ""
   |                        ^^
   |              Found:    String("")
   |              Required: Test.T[X]
   |              
   |              where:    X is a type in method f which is an alias of Int

If I swap the two cases in the match type the error is on the next line. This seems to indicate that the problem is in the no-overlap checks for match types. Maybe it needs to be strengthened for GADT aliases.

Generally:

  • it would be good to play with more cases like this one
  • it would be good to invest effort in better diagnostics when no-overlap check fails.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions