From a633601fec4bd1a86545a9fbec2e79a2b69e35fe Mon Sep 17 00:00:00 2001 From: Nicolas Stucki <nicolas.stucki@gmail.com> Date: Tue, 21 May 2019 16:15:55 +0200 Subject: [PATCH] Fix #6535: Add missing span --- .../tools/dotc/transform/PostTyper.scala | 2 +- tests/pos-macros/i6535/Macro_1.scala | 29 +++++++++++++++++++ tests/pos-macros/i6535/Test_2.scala | 9 ++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i6535/Macro_1.scala create mode 100644 tests/pos-macros/i6535/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index fd3110ba2d03..69b4ebcb41ad 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -122,7 +122,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase case pkg: PackageClassDenotation => val pobj = pkg.packageObjFor(tree.symbol) if (pobj.exists) - return transformSelect(cpy.Select(tree)(qual.select(pobj), tree.name), targs) + return transformSelect(cpy.Select(tree)(qual.select(pobj).withSpan(qual.span), tree.name), targs) case _ => } val tree1 = super.transform(tree) diff --git a/tests/pos-macros/i6535/Macro_1.scala b/tests/pos-macros/i6535/Macro_1.scala new file mode 100644 index 000000000000..10042e56adc3 --- /dev/null +++ b/tests/pos-macros/i6535/Macro_1.scala @@ -0,0 +1,29 @@ +import scala.quoted._ +import scala.tasty._ + +object scalatest { + + inline def assert(condition: => Boolean): Unit = ${ assertImpl('condition) } + + def assertImpl(cond: Expr[Boolean])(implicit refl: Reflection): Expr[Unit] = { + import refl._ + import util._ + + cond.unseal.underlyingArgument match { + case t @ Apply(Select(lhs, op), rhs :: Nil) => + let(lhs) { left => + let(rhs) { right => + val app = Select.overloaded(left, op, Nil, right :: Nil) + let(app) { result => + val l = left.seal + val r = right.seal + val b = result.seal.cast[Boolean] + val code = '{ scala.Predef.assert($b) } + code.unseal + } + } + }.seal.cast[Unit] + } + } + +} diff --git a/tests/pos-macros/i6535/Test_2.scala b/tests/pos-macros/i6535/Test_2.scala new file mode 100644 index 000000000000..0969d8d42c2c --- /dev/null +++ b/tests/pos-macros/i6535/Test_2.scala @@ -0,0 +1,9 @@ +object Test { + import scalatest._ + + def neverRuns(f: => Unit): Boolean = true + + def main(args: Array[String]): Unit = { + assert(this.neverRuns(sys.error("Sad times 1"))) + } +} \ No newline at end of file