Search code examples
scalamacrospartialfunction

Scala: 'missing parameter type' when calling scala macro with a PartialFunction reify


The compiler is throwing me a 'Missing parameter type'. After cornering the problem I've realized that when chaining Partial Functions you need to be explicit about the types or the compiler will throw the mentioned error. Now, do you guys know if there are any issues when chaining partial functions inside a macro's reify? I think I couldn't be more explicit about the partial function types:

object Implementations{
      def missingParamType_impl(c: whitebox.Context)(a: c.Expr[Int]):c.Expr[PartialFunction[Int,String]] = {
        import c.universe._

        reify {
          val spliced = a.splice
          val spliced2 = a.splice * 2
          ((PartialFunction.apply[Int,String]{
            case `spliced` ⇒ a.splice.toString
          } : PartialFunction[Int,String]).orElse[Int,String]{
            case `spliced2` ⇒ a.splice.toString
          } : PartialFunction[Int,String]) : PartialFunction[Int,String]
        }
      }
}

This is how I call the macro implementation:

object Macros {
def missingParamType(a: Int):PartialFunction[Int,String] = macro Implementations.missingParamType_impl
}

I have also tried this:

def missingParamType_impl(c: whitebox.Context)(a: c.Expr[Int]):c.Expr[PartialFunction[Int,String]] = {
    import c.universe._

    reify {
      val spliced = a.splice
      val spliced2 = a.splice * 2
      val pf1: PartialFunction[Int, String] = {
        case `spliced` ⇒ a.splice.toString
      }
      val pf2: PartialFunction[Int, String] = {
        case `spliced2` ⇒ a.splice.toString
      }
      val PF:PartialFunction[Int, String] = pf1.orElse(pf2)
      PF
    }
  }

Or am I fundamentally misunderstanding how reify works?


Solution

  • Unfortunately, this looks like a known issue: https://issues.scala-lang.org/browse/SI-6619.