Skip to content

Commit fb1e834

Browse files
committed
Set correct source for generated TypeTrees
Fixes #13352
1 parent 02642db commit fb1e834

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,10 +1375,12 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
13751375
def tpe: TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds]
13761376
def low: TypeTree = self match
13771377
case self: tpd.TypeBoundsTree => self.lo
1378-
case self: tpd.TypeTree => tpd.TypeTree(self.tpe.asInstanceOf[Types.TypeBounds].lo).withSpan(self.span)
1378+
case self: tpd.TypeTree => makeTypeDef(self.tpe.asInstanceOf[Types.TypeBounds].lo)
13791379
def hi: TypeTree = self match
13801380
case self: tpd.TypeBoundsTree => self.hi
1381-
case self: tpd.TypeTree => tpd.TypeTree(self.tpe.asInstanceOf[Types.TypeBounds].hi).withSpan(self.span)
1381+
case self: tpd.TypeTree => makeTypeDef(self.tpe.asInstanceOf[Types.TypeBounds].hi)
1382+
private def makeTypeDef(tpe: Types.Type) =
1383+
tpd.TypeTree(tpe)(using ctx.withSource(self.source)).withSpan(self.span)
13821384
end extension
13831385
end TypeBoundsTreeMethods
13841386

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import scala.quoted.*
2+
import scala.tasty.inspector.*
3+
4+
@main def Test = {
5+
// Artefact of the current test infrastructure
6+
// TODO improve infrastructure to avoid needing this code on each test
7+
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(_.contains("runWithCompiler")).get
8+
val allTastyFiles = dotty.tools.io.Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList
9+
val tastyFiles = allTastyFiles.filter(_.contains("CanEqual2"))
10+
11+
TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector)
12+
}
13+
14+
class MyInspector extends Inspector:
15+
16+
override def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
17+
import quotes.reflect.*
18+
class Traverser extends TreeTraverser:
19+
override def traverseTree(tree: Tree)(owner: Symbol) =
20+
if tree.pos.startLine < 100 then
21+
super.traverseTree(tree)(owner)
22+
end Traverser
23+
24+
val traverser = new Traverser
25+
tastys.foreach { tasty =>
26+
traverser.traverseTree(tasty.ast)(tasty.ast.symbol)
27+
}
28+
29+
30+
class CanEqual2[T]

0 commit comments

Comments
 (0)