Skip to content

Macro fails to match on more specific case: HList example  #10358

Closed
@hmf

Description

@hmf

Minimized code

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

  private def flattenImpl[Xs <: HList](e: Expr[Xs])(using xt:Type[Xs], qctx:QuoteContext):
  Expr[_ <:HList] = {
    import qctx.reflect._

    e match {
      case '{HNil} =>
        '{HNil}

      //case '{HCons($h, $_)} =>
      case '{HCons($h, HCons($_,$_))} =>
        '{???}

      case _ =>
        report.error(s"flattenImpl ???????  ${e.show}", e); '{???}
    }
  }


  transparent inline def flattenM[Xs <: HList](inline xs: Xs): Any = {
    ${flattenImpl('xs)}
  }

  val ffl00: HCons[Int, HCons[Int, HNil.type]] = flattenM( HCons(0, HCons(1, HNil)) )

Output

[error] -- Error: HyperParameters.scala:448:66 
[error] 448 |    val ffl00: HCons[Int, HCons[Int, HNil.type]] = flattenM( HCons(0, HCons(1, HNil)) )
[error]     |                                                             ^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |flattenImpl ???????  automl.Recorder.HCons.apply[scala.Int, automl.Recorder.HCons[scala.Int, automl.Recorder.HNil]](0, automl.Recorder.HCons.apply[scala.Int, automl.Recorder.HNil.type](1, automl.Recorder.HNil))
[error]     | This location contains code that was inlined from HyperParameters.scala:448

Expectation

I expected the match to succeed. If I use the more general case that is commented out, the match occurs.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions