Skip to content

Match type reduction depends on scope #9623

Closed
@rnd4222

Description

@rnd4222

The problem

Looks like match type reduction depends on where type was defined (or, maybe, if its sealed or not at definition side).
Following example don't compiles on 0.26.0-RC1, but moving TList definition to a toplevel makes it compile.

Minimized code

object A {
  // Move this 3 definitions to a toplevel to make it compile
  sealed trait TList
  sealed trait TNil extends TList
  sealed trait ++:[H, T <: TList] extends TList

  type :--[R <: TList, A] <: TList = R match {
    case (A ++: t) => t
    case (h ++: t) => h ++: (t :-- A)
  }
}

object B {
  import A.{given _, _}

  type X = (Int ++: String ++: Double ++: TNil) :-- String

  class T[A]

  def f(ta: T[X]) = ()

  f(new T[Int ++: Double ++: TNil])
}

Output

[error] 41 |  f(new T[Int ++: Double ++: TNil])
[error]    |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |    Found:    B.T[Int ++: Double ++: A.TNil]
[error]    |    Required: B.T[B.X]

Expectation

Code compiles successfully.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions