【问题标题】:What happened to the macros API in Scala 2.11?Scala 2.11 中的宏 API 发生了什么变化?
【发布时间】:2013-12-10 09:05:28
【问题描述】:

我正在尝试将宏从 Scala 2.10 移植到 2.11.0-M7:

import scala.reflect.macros.Context

object Format {
  def apply[A]: Unit = macro applyImpl[A]

  def applyImpl[A: c.WeakTypeTag](c: Context): c.Expr[Unit] = ???
}

一定有什么改变了,因为编译器说scala.reflect.macros.Context不存在。

我的构建文件如下所示:

scalaVersion := "2.11.0-M7"

resolvers += Resolver.sonatypeRepo("snapshots")

addCompilerPlugin("org.scala-lang.plugins" % "macro-paradise" % "2.0.0-SNAPSHOT"
  cross CrossVersion.full)

有什么线索吗?

【问题讨论】:

    标签: scala macros scala-2.11


    【解决方案1】:

    现在需要明确添加scala-reflect

    libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
    

    Context 已弃用,但可以编译。

    【讨论】:

    • 我认为总是有必要明确地依赖 scala-reflect。
    • @EugeneBurmako - 实际上,不,我的库在 2.10 中编译 without explicit reflect;反正没什么大问题,现在可以了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 2019-02-09
    • 1970-01-01
    相关资源
    最近更新 更多