From 58e8b8e108850788497bf5bab8b6382694ef20cb Mon Sep 17 00:00:00 2001 From: Yang Bo Date: Fri, 26 Jul 2019 23:59:06 -0700 Subject: [PATCH] Don't transform macros (fix #280) --- compilerplugins-ResetEverywhere/build.sbt | 2 ++ .../dsl/compilerplugins/ResetEverywhere.scala | 2 ++ .../dsl/compilerplugins/Issue280.scala | 20 +++++++++++++++++++ .../thoughtworks/dsl/keywords/YieldSpec.scala | 11 ++++++++++ 4 files changed, 35 insertions(+) create mode 100644 compilerplugins-ResetEverywhere/src/test/scala/com/thoughtworks/dsl/compilerplugins/Issue280.scala diff --git a/compilerplugins-ResetEverywhere/build.sbt b/compilerplugins-ResetEverywhere/build.sbt index 02a6401fc..45aa60c88 100644 --- a/compilerplugins-ResetEverywhere/build.sbt +++ b/compilerplugins-ResetEverywhere/build.sbt @@ -7,3 +7,5 @@ scalacOptions ++= { Seq() } } + +scalacOptions in Test += raw"""-Xplugin:${(packageBin in Compile).value}""" diff --git a/compilerplugins-ResetEverywhere/src/main/scala/com/thoughtworks/dsl/compilerplugins/ResetEverywhere.scala b/compilerplugins-ResetEverywhere/src/main/scala/com/thoughtworks/dsl/compilerplugins/ResetEverywhere.scala index 4b265aa8e..56bf8a5ea 100644 --- a/compilerplugins-ResetEverywhere/src/main/scala/com/thoughtworks/dsl/compilerplugins/ResetEverywhere.scala +++ b/compilerplugins-ResetEverywhere/src/main/scala/com/thoughtworks/dsl/compilerplugins/ResetEverywhere.scala @@ -100,6 +100,8 @@ final class ResetEverywhere(override val global: Global) extends Plugin { body.mapConserve { case valDef: ValDef if !valDef.mods.isParamAccessor => transformRootValDef(valDef) + case defDef: DefDef if defDef.mods.hasFlag(Flag.MACRO) => + defDef case initializer: TermTree => annotatedReset(initializer) case stat => diff --git a/compilerplugins-ResetEverywhere/src/test/scala/com/thoughtworks/dsl/compilerplugins/Issue280.scala b/compilerplugins-ResetEverywhere/src/test/scala/com/thoughtworks/dsl/compilerplugins/Issue280.scala new file mode 100644 index 000000000..ec34c0f4a --- /dev/null +++ b/compilerplugins-ResetEverywhere/src/test/scala/com/thoughtworks/dsl/compilerplugins/Issue280.scala @@ -0,0 +1,20 @@ +package com.thoughtworks.dsl.compilerplugins + +object Issue280 { + import scala.language.experimental.macros + + object ContainsMacro { + + def apply: String = macro Macros.apply + + } + + class Macros(val c: scala.reflect.macros.blackbox.Context) { + + import c.universe._ + + def apply: Tree = q"???" + + } + +} diff --git a/keywords-Yield/src/test/scala/com/thoughtworks/dsl/keywords/YieldSpec.scala b/keywords-Yield/src/test/scala/com/thoughtworks/dsl/keywords/YieldSpec.scala index 915ba8ab6..2df687688 100644 --- a/keywords-Yield/src/test/scala/com/thoughtworks/dsl/keywords/YieldSpec.scala +++ b/keywords-Yield/src/test/scala/com/thoughtworks/dsl/keywords/YieldSpec.scala @@ -13,6 +13,17 @@ import scala.runtime.NonLocalReturnControl */ class YieldSpec extends FreeSpec with Matchers { + { + !Yield(1) + + def nested(): Stream[Int] = { + !Yield(2) + Stream.empty[Int] + } + + nested() + } // Should compile + "Given a continuation that uses Yield and Each expressions" - { def asyncFunction: Stream[String] !! Unit = _ {