Skip to content

Cannot reduce inline match with an enum-based Nat #6781

Closed
@biboudis

Description

@biboudis

minimized code

  enum Nat {
    case Zero
    case Succ[N <: Nat](n: N)
  }
  import Nat._

  inline def toInt(n: => Nat): Int = inline n match {
    case Zero => 0
    case Succ(n1) => toInt(n1) + 1
  }

  val natTwo = toInt(Succ(Succ(Zero)))

results in a compile time error:

inline n match {
   |                                     ^
   |                                     cannot reduce delegate match with
   |                                      scrutinee:  {
   |                                       App.Nat.Succ.apply[App.Nat](App.Nat.Succ.apply[App.Nat](App.Nat$#Zero))
   |                                     } : App.Nat
   |                                      patterns :  case App.Nat$#Zero
   |                                                  case App.Nat.Succ.unapply[N$1 @ N$1](n1 @ _):App.Nat.Succ[N$1]

expectation

To work as the "old" encoding:

trait Nat
case object Zero extends Nat
case class Succ[N <: Nat](n: N) extends Nat 

nitpick: the error message should have been about inline match instead of delegate

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions