From 218112b9deec2dd0249124654a613a829b34cc86 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Wed, 7 Aug 2019 17:45:35 +0200 Subject: [PATCH 1/2] Fix #7008: dealias temporary types in pickling types --- .../dotc/core/quoted/PickledQuotes.scala | 3 ++- tests/run-macros/i7008/macro_1.scala | 19 +++++++++++++++++++ tests/run-macros/i7008/test_2.scala | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/run-macros/i7008/macro_1.scala create mode 100644 tests/run-macros/i7008/test_2.scala diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index fbac02bebd8c..f3581b205bc0 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -72,12 +72,13 @@ object PickledQuotes { def unpickleType(tasty: PickledQuote, args: PickledTypeArgs)(implicit ctx: Context): Tree = { val tastyBytes = TastyString.unpickle(tasty) val unpickled = unpickle(tastyBytes, args, isType = true)(ctx.addMode(Mode.ReadPositions)) - unpickled match { + val tpt = unpickled match { case Block(aliases, tpt) => // `@quoteTypeTag type` aliasses are not required after unpickling tpt case tpt => tpt } + tpt.withType(dealiasTypeTags(tpt.tpe)) } // TASTY picklingtests/pos/quoteTest.scala diff --git a/tests/run-macros/i7008/macro_1.scala b/tests/run-macros/i7008/macro_1.scala new file mode 100644 index 000000000000..ef270cfd14a3 --- /dev/null +++ b/tests/run-macros/i7008/macro_1.scala @@ -0,0 +1,19 @@ +import scala.quoted._, scala.quoted.matching._ +import delegate scala.quoted._ +import scala.tasty._ + +case class Box[T](v: T) + +inline def mcr(expr: => Boolean): Unit = ${mcrProxy('expr)} + +def mcrProxy(expr: Expr[Boolean]) given QuoteContext: Expr[Unit] = { + val res = mcrImpl[Boolean]('{ (esx: Seq[Box[Boolean]]) => () }, expr) + // println(s"Out: ${res.show}") + res +} + +def mcrImpl[T](func: Expr[Seq[Box[T]] => Unit], expr: Expr[T]) given (ctx: QuoteContext, tt: Type[T]): Expr[Unit] = { + import ctx.tasty._ + val arg = Seq('{(Box($expr))}).toExprOfSeq + func(arg) +} \ No newline at end of file diff --git a/tests/run-macros/i7008/test_2.scala b/tests/run-macros/i7008/test_2.scala new file mode 100644 index 000000000000..bc12d6ab9576 --- /dev/null +++ b/tests/run-macros/i7008/test_2.scala @@ -0,0 +1 @@ +@main def Test = println(mcr(true)) \ No newline at end of file From cd9b3f8cdef0312c4282a3904bf6e617c1a98825 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Sun, 11 Aug 2019 13:40:48 +0200 Subject: [PATCH 2/2] Adapt test to pass CI The cause of the failure is reported in the following PR: https://github.com/lampepfl/dotty/issues/7017 Once that issue is fixed, we should re-enable the following test scala> object O // defined object O scala> withQuoteContext { fn(O) } ok --- compiler/test-resources/repl-macros/i6263 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler/test-resources/repl-macros/i6263 b/compiler/test-resources/repl-macros/i6263 index 4b3df71a76b0..2bb2b18f91e9 100644 --- a/compiler/test-resources/repl-macros/i6263 +++ b/compiler/test-resources/repl-macros/i6263 @@ -7,9 +7,5 @@ scala> withQuoteContext { fn("foo") } ok scala> withQuoteContext { fn((1,2)) } ok -scala> object O -// defined object O -scala> withQuoteContext { fn(O) } -ok scala> withQuoteContext { fn(1) } ok