diff --git a/main/settings/KeyMacro.scala b/main/settings/KeyMacro.scala index 7d7c2ee6e..c35819e8f 100644 --- a/main/settings/KeyMacro.scala +++ b/main/settings/KeyMacro.scala @@ -32,12 +32,13 @@ object KeyMacro { import c.universe.{Apply=>ApplyTree,_} val methodName = c.macroApplication.symbol.name.decoded - val enclosingTrees = c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.context.enclosingContextChain.map(_.tree.asInstanceOf[Tree]) - enclosingTrees match { + enclosingTrees(c) match { case vd @ ValDef(_, name, _, _) :: ts => name.decoded case _ => c.error(c.enclosingPosition, s"""$methodName must be directly assigned to a val, such as `val x = $methodName[Int]("description")`.""") "" } } + def enclosingTrees(c: Context): Seq[c.Tree] = + c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.context.enclosingContextChain.map(_.tree.asInstanceOf[c.Tree]) } \ No newline at end of file