Skip to content

Commit 30de364

Browse files
committed
Handle SummonFrom in reflect TreeAccumulator
Fixes #14789
1 parent 2b88a27 commit 30de364

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4621,6 +4621,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
46214621
case Bind(_, body) => foldTree(x, body)(owner)
46224622
case Unapply(fun, implicits, patterns) => foldTrees(foldTrees(foldTree(x, fun)(owner), implicits)(owner), patterns)(owner)
46234623
case Alternatives(patterns) => foldTrees(x, patterns)(owner)
4624+
case SummonFrom(cases) => foldTrees(x, cases)(owner)
46244625
case _ => throw MatchError(tree.show(using Printer.TreeStructure))
46254626
}
46264627
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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("App"))
10+
11+
// in dotty-example-project
12+
val inspector = new Inspector {
13+
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit = {
14+
import quotes.reflect.*
15+
val traverser = new TreeTraverser {
16+
override def traverseTree(tree: Tree)(owner: Symbol): Unit = {
17+
try {
18+
super.traverseTree(tree)(owner)
19+
} catch {
20+
case e =>
21+
report.error(s"unexpected error ${e}", tree.pos)
22+
throw e
23+
}
24+
}
25+
}
26+
tastys.foreach{ tasty =>
27+
traverser.traverseTree(tasty.ast)(tasty.ast.symbol)
28+
}
29+
}
30+
}
31+
TastyInspector.inspectTastyFiles(tastyFiles)(inspector)
32+
}
33+
34+
object App {
35+
import scala.compiletime.*
36+
37+
transparent inline def summonFirst0[T]: Any =
38+
inline erasedValue[T] match
39+
case _: (a *: b) => summonFrom {
40+
case instance: `a` => instance
41+
case _ => summonFirst0[b]
42+
}
43+
}

0 commit comments

Comments
 (0)