Skip to content

Set correct source for generated TypeTrees #13465

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
Sep 7, 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
6 changes: 4 additions & 2 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions tests/run-custom-args/tasty-inspector/i13352.scala
Original file line number Diff line number Diff line change
@@ -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]