Skip to content

Sealed traits behave different than sealed class for type match reduction #13455

Closed
@jrudolph

Description

@jrudolph

Compiler version

3.0.1

Minimized code

  sealed class R

  type X[T] = T match {
    case R        => String
    case (z => r) => Int
  }
  def x[T]: X[T] = ???
  
  def i(i0: Int): Unit = ???
  i(x[Int => String])

This match type fails with

[error] 30 |  i(x[Int => String])
[error]    |    ^^^^^^^^^^^^^^^^
[error]    |    Found:    X[Int => String]
[error]    |    Required: Int
[error]    |
[error]    |    Note: a match type could not be fully reduced:
[error]    |
[error]    |      trying to reduce  X[Int => String]
[error]    |      failed since selector  Int => String
[error]    |      does not match  case R => String
[error]    |      and cannot be shown to be disjoint from it either.
[error]    |      Therefore, reduction cannot advance to the remaining case
[error]    |
[error]    |        case z => r => Int

when the same example with

  sealed trait R

works?

Expectation

Both examples compile.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions