Skip to content

Nested transparent call does not refine the type #8739

Open
@nicolasstucki

Description

@nicolasstucki

Minimized code

trait HList
case object HNil extends HList
case class HCons[H, T <: HList](h: H, t: T) extends HList

transparent inline def concat(inline x: HList, inline y: HList): HList =
  inline x match
    case HNil => y
    case HCons(h, t) =>
      val tail = concat(t, y)
      HCons(h, tail)

val d: HCons[Int, HCons[String, HNil.type]] = concat(HCons(1, HNil), HCons("2", HNil))

Output

12 |val d: HCons[Int, HCons[String, HNil.type]] = concat(HCons(1, HNil), HCons("2", HNil))
   |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                          Found:    HCons[Int, HList]
   |                          Required: HCons[Int, HCons[String, HNil.type]]

After typer the code is

    val d: HCons[Int, HCons[String, HNil.type]] = 
      {
        {
          val h: (1 : Int) = 1
          val $elem2: HNil$ = HNil
          val t: HNil$ = $elem2
          val tail: HList = // this type should have beein refined to HCons[String, HNil.type]
            {
              {
                {
                  HCons.apply[String, HNil.type]("2", HNil)
                }
              }
            }
          HCons.apply[Int, HList](h, tail)
        }
      }

Expectation

It should compile

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions