From dd2a5d0e158f83302354cdf56ad587d0c1258258 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 18 Dec 2020 10:45:56 +0100 Subject: [PATCH] Fix #10127: Don't try to get tags after error The tags may be unavailablle due to the error. --- .../dotty/tools/dotc/transform/PCPCheckAndHeal.scala | 7 +++++-- tests/neg-macros/i10127-a.scala | 8 ++++++++ tests/neg-macros/i10127-b.scala | 10 ++++++++++ tests/pos-macros/i10127.scala | 8 ++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/neg-macros/i10127-a.scala create mode 100644 tests/neg-macros/i10127-b.scala create mode 100644 tests/pos-macros/i10127.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 724971d869f8..15d76b88a13f 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -140,8 +140,11 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( protected def transformSpliceType(body: Tree, splice: Select)(using Context): Tree = { val body1 = transform(body)(using spliceContext) - val tagRef = getQuoteTypeTags.getTagRef(splice.qualifier.tpe.asInstanceOf[TermRef]) - ref(tagRef).withSpan(splice.span) + if ctx.reporter.hasErrors then + splice + else + val tagRef = getQuoteTypeTags.getTagRef(splice.qualifier.tpe.asInstanceOf[TermRef]) + ref(tagRef).withSpan(splice.span) } /** Check that annotations do not contain quotes and and that splices are valid */ diff --git a/tests/neg-macros/i10127-a.scala b/tests/neg-macros/i10127-a.scala new file mode 100644 index 000000000000..c62dab8b7ac2 --- /dev/null +++ b/tests/neg-macros/i10127-a.scala @@ -0,0 +1,8 @@ +import scala.quoted._ + +object T { + def impl[A](using t: Type[A])(using Quotes): Expr[Unit] = { + Expr.summon[t.Underlying] // error + '{} + } +} \ No newline at end of file diff --git a/tests/neg-macros/i10127-b.scala b/tests/neg-macros/i10127-b.scala new file mode 100644 index 000000000000..8c69ea5444c1 --- /dev/null +++ b/tests/neg-macros/i10127-b.scala @@ -0,0 +1,10 @@ +import scala.quoted._ + +case class T(x: Type[_ <: Any]) + +object T { + def impl[A](t: T)(using ctx: Quotes): Expr[Unit] = { + Expr.summon[t.x.Underlying] // error // error + '{} + } +} \ No newline at end of file diff --git a/tests/pos-macros/i10127.scala b/tests/pos-macros/i10127.scala new file mode 100644 index 000000000000..ccd710728d21 --- /dev/null +++ b/tests/pos-macros/i10127.scala @@ -0,0 +1,8 @@ +import scala.quoted._ + +object T { + def impl[A](using Type[A])(using Quotes): Expr[Unit] = { + Expr.summon[A] + '{} + } +} \ No newline at end of file