From fb1e834669aa3e1555f229d74d137d4ecd956f12 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 3 Sep 2021 13:47:38 +0200 Subject: [PATCH] Set correct source for generated TypeTrees Fixes #13352 --- .../quoted/runtime/impl/QuotesImpl.scala | 6 ++-- .../tasty-inspector/i13352.scala | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/run-custom-args/tasty-inspector/i13352.scala diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 4c16871db1d1..80c6dc757aaa 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1375,10 +1375,12 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def tpe: TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds] def low: TypeTree = self match case self: tpd.TypeBoundsTree => self.lo - case self: tpd.TypeTree => tpd.TypeTree(self.tpe.asInstanceOf[Types.TypeBounds].lo).withSpan(self.span) + case self: tpd.TypeTree => makeTypeDef(self.tpe.asInstanceOf[Types.TypeBounds].lo) def hi: TypeTree = self match case self: tpd.TypeBoundsTree => self.hi - case self: tpd.TypeTree => tpd.TypeTree(self.tpe.asInstanceOf[Types.TypeBounds].hi).withSpan(self.span) + case self: tpd.TypeTree => makeTypeDef(self.tpe.asInstanceOf[Types.TypeBounds].hi) + private def makeTypeDef(tpe: Types.Type) = + tpd.TypeTree(tpe)(using ctx.withSource(self.source)).withSpan(self.span) end extension end TypeBoundsTreeMethods diff --git a/tests/run-custom-args/tasty-inspector/i13352.scala b/tests/run-custom-args/tasty-inspector/i13352.scala new file mode 100644 index 000000000000..d5b319a7e548 --- /dev/null +++ b/tests/run-custom-args/tasty-inspector/i13352.scala @@ -0,0 +1,30 @@ +import scala.quoted.* +import scala.tasty.inspector.* + +@main def Test = { + // Artefact of the current test infrastructure + // TODO improve infrastructure to avoid needing this code on each test + val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(_.contains("runWithCompiler")).get + val allTastyFiles = dotty.tools.io.Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList + val tastyFiles = allTastyFiles.filter(_.contains("CanEqual2")) + + TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector) +} + +class MyInspector extends Inspector: + + override def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit = + import quotes.reflect.* + class Traverser extends TreeTraverser: + override def traverseTree(tree: Tree)(owner: Symbol) = + if tree.pos.startLine < 100 then + super.traverseTree(tree)(owner) + end Traverser + + val traverser = new Traverser + tastys.foreach { tasty => + traverser.traverseTree(tasty.ast)(tasty.ast.symbol) + } + + +class CanEqual2[T]