如何将宏注释应用于具有上下文绑定的案例类?

SII*_*SII 5 scala case-class context-bound scala-macros

当我尝试向我的case类添加宏注释时:

@macid case class CC[A: T](val x: A)
Run Code Online (Sandbox Code Playgroud)

我收到错误:

private[this] not allowed for case class parameters
Run Code Online (Sandbox Code Playgroud)

@macid 只是身份函数,定义为whitebox StaticAnnotation:

import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context
import scala.annotation.StaticAnnotation
class macid extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro macidMacro.impl
}
object macidMacro {
  def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
    new Macros[c.type](c).macidMacroImpl(annottees.toList)
  }
}
class Macros[C <: Context](val c: C) {
  import c.universe._
  def macidMacroImpl(annottees: List[c.Expr[Any]]): c.Expr[Any] =
    annottees(0)
}
Run Code Online (Sandbox Code Playgroud)

未注释的代码有效:

case class CC[A: T](val x: A)
Run Code Online (Sandbox Code Playgroud)

如果我删除上下文绑定它是有效的:

@macid case class CC[A](val x: A)
Run Code Online (Sandbox Code Playgroud)

发生的事情是将上下文绑定到私有参数中.以下desugared代码得到相同的错误:

@macid case class CC[A](val x: A)(implicit aIsT: T[A])
Run Code Online (Sandbox Code Playgroud)

为了获得工作代码,我将隐式参数设为public val:

@macid case class CC[A](val x: A)(implicit val aIsT: T[A])
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:宏注释支持上下文边界的正确方法是什么?为什么编译器对由宏注释生成的代码执行no-private-parameters-of-case-classes检查,但是不执行对普通代码的检查?

Scala版本2.11.7和2.12.0-M3都报告错误.所有上面的代码示例都按照2.11.3中的预期编译和运行.

Mic*_*jac 2

看起来像一个错误。这是宏所看到的树:

case class CC[A] extends scala.Product with scala.Serializable {
  <caseaccessor> <paramaccessor> val x: A = _;
  implicit <synthetic> <caseaccessor> <paramaccessor> private[this] val evidence$1: T[A] = _;
  def <init>(x: A)(implicit evidence$1: T[A]) = {
    super.<init>();
    ()
  }
}
Run Code Online (Sandbox Code Playgroud)

并通过运行时反射 API:

case class CC[A] extends Product with Serializable {
  <caseaccessor> <paramaccessor> val x: A = _;
  implicit <synthetic> <paramaccessor> private[this] val evidence$1: $read.T[A] = _;
  def <init>(x: A)(implicit evidence$1: $read.T[A]) = {
    super.<init>();
    ()
  }
};
Run Code Online (Sandbox Code Playgroud)

前者在不应该的情况下有一个额外的<caseaccessor>标志。evidence$1似乎案例类的所有隐式参数都被错误地赋予了此标志。