Skip to content

Fix #10127: Don't try to get tags after error #10851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to transform the body for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to. That tree will not be used after the error. We could return body1.select(...).with span(...) but it might just complicate the code for no practical reason.

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 */
Expand Down
8 changes: 8 additions & 0 deletions tests/neg-macros/i10127-a.scala
Original file line number Diff line number Diff line change
@@ -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
'{}
}
}
10 changes: 10 additions & 0 deletions tests/neg-macros/i10127-b.scala
Original file line number Diff line number Diff line change
@@ -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
'{}
}
}
8 changes: 8 additions & 0 deletions tests/pos-macros/i10127.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted._

object T {
def impl[A](using Type[A])(using Quotes): Expr[Unit] = {
Expr.summon[A]
'{}
}
}