Skip to content

Match type reduction failure #19326

Open
@Bersier

Description

@Bersier

Compiler version

3.4.0-RC1, 3.4.0-RC1-bin-20231221-beaf7b4-NIGHTLY

Minimized code

import OpaqueScope.Opaque

type MapSum[D1, D2] = D1 match
  case Opaque[l1] => D2 match
    case Opaque[l2] => Opaque[Sum[l1, l2]]

object OpaqueScope:
  opaque type Opaque[N <: NatT] = Double

  val foo: MapSum[Opaque[Succ[Zero]], Opaque[Zero]] = 1.0
end OpaqueScope

sealed trait NatT derives CanEqual
case class Zero() extends NatT
case class Succ[N <: NatT](n: N) extends NatT

type Sum[M <: NatT, N <: NatT] <: NatT = (M, N) match
  case (_, Zero) => M
  case (Zero, _) => N
  case (Succ[predM], Succ[predN]) => Succ[Succ[Sum[predM, predN]]]

Compiler output

[error] 10 |  val foo: OpaqueSum[Opaque[Succ[Zero]], Opaque[Zero]] = 1.0
[error]    |                                                         ^^^
[error]    |Found:    (1.0d : Double)
[error]    |Required: OpaqueSum[OpaqueScope.Opaque[Succ[Zero]], OpaqueScope.Opaque[Zero]]
[error]    |
[error]    |Note: a match type could not be fully reduced:
[error]    |
[error]    |  trying to reduce  OpaqueSum[OpaqueScope.Opaque[Succ[Zero]], OpaqueScope.Opaque[Zero]]
[error]    |  failed since selector OpaqueScope.Opaque[Succ[Zero]]
[error]    |  does not match  case OpaqueScope.Opaque[l1] => OpaqueScope.Opaque[Zero] match {
[error]    |  case OpaqueScope.Opaque[l2] => OpaqueScope.Opaque[Sum[l1, l2]]
[error]    |}
[error]    |  and cannot be shown to be disjoint from it either.
[error]    |
[error]    | longer explanation available when compiling with `-explain`

Expectation

The code is expected to compile, as in Scala 3.3.1 and 3.3.2-RC1.

(See also here)

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