[SOLVED] Dotty / Scala3 match types: flattening an HList

I am trying to take an HList type that can itself have elements that are HLists and flatten it. My initial attempt was:

  type Concat[Xs <: HList, Ys <: HList] <: HList = Xs match {
    case HNil.type => Ys
    case HCons[x1, xs1] => HCons[x1, Concat[xs1, Ys]]
  }

  type Flatten[Xs <: HList] <: HList = Xs match {
    case HCons[HCons[h1,t1], t] => Concat[Flatten[HCons[h1,t1]], Flatten[t]]
    case HCons[h, t] => HCons[h, Flatten[t]]
    case HNil.type => HNil.type
  }

  summon[Flatten[HCons[
                     HCons[1,HCons[2, HNil.type]],
                        HCons[3, HNil.type]
                        ]
                   ] =:= HCons[1,HCons[2,HCons[3,HNil.type]]] ]

The above Flatten does not work. After some experimentation I found that case HCons[h, t] => subsumes the more specific case HCons[HCons[h1,t1], t] => - so the h will match any type including an HCons.

I have considered trying to enforce type inequality in the match cases but this is out of my league.

Does anyone know how do do this or know were I can get info on how to do this?

TIA

Possible issue:

For the record this is now working in 3.0.0-M2. Here is a working example:

  sealed trait HList
  case class HCons[+HD, TL <: HList](hd: HD, tl: TL) extends HList
  case object HNil extends HList


  type Concat[Xs <: HList, Ys <: HList] <: HList = Xs match {
    case HNil.type => Ys
    case HCons[x1, xs1] => HCons[x1, Concat[xs1, Ys]]
  }

  type Flatten[Xs <: HList] <: HList = Xs match {
    case HNil.type => HNil.type
    case HCons[HCons[h1, HNil.type], HNil.type] => HCons[h1, HNil.type]
    case HCons[HCons[h1, t1], HNil.type] => HCons[h1,t1]
    case HCons[HCons[h1,t1], t] => Concat[Flatten[HCons[h1,t1]], Flatten[t]]
    case HCons[h, t] => HCons[h, Flatten[t]]
  }

    summon[Flatten[HNil.type] =:= HNil.type]
    summon[Flatten[HCons[HCons[1,HNil.type], HNil.type]] =:= HCons[1,HNil.type] ]
    summon[Flatten[HCons[HCons[1,HNil.type], HNil.type]] =:= HCons[1,HNil.type] ]
    summon[Flatten[HCons[1,HCons[HCons[2,HNil.type], HNil.type]]] =:= HCons[1,HCons[2,HNil.type]] ]
    summon[Flatten[HCons[1,
                     HCons[
                           HCons[2, HCons[3, HNil.type]],
                             HCons[4, HNil.type]
                          ]
                         ]
                   ] =:= HCons[1, HCons[2, HCons[3, HCons[4, HNil.type]]]]]
    summon[Flatten[HCons[
                     HCons[1,HCons[2, HNil.type]],
                       HCons[3, HNil.type] ] ]
      =:= HCons[1,HCons[2,HCons[3,HNil.type]]] ]