|
| 1 | + |
| 2 | +import scala.quoted.* |
| 3 | +import scala.tasty.inspector.Inspector |
| 4 | +import scala.tasty.inspector.Tasty |
| 5 | +import scala.tasty.inspector.TastyInspector |
| 6 | +import scala.reflect.ClassTag |
| 7 | + |
| 8 | +import scala.quoted.* |
| 9 | +import scala.tasty.inspector.* |
| 10 | + |
| 11 | +@main def Test: Unit = { |
| 12 | + // Artefact of the current test infrastructure |
| 13 | + // TODO improve infrastructure to avoid needing this code on each test |
| 14 | + val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(this.getClass.getClassLoader).split(java.io.File.pathSeparator).find(_.contains("runWithCompiler")).get |
| 15 | + val allTastyFiles = dotty.tools.io.Path(classpath).walkFilter(_.extension == "tasty").map(_.toString).toList |
| 16 | + val tastyFiles = allTastyFiles.filter(_.contains("MySeq")) |
| 17 | + |
| 18 | + TastyInspector.inspectTastyFiles(tastyFiles)(new MyInspector) |
| 19 | +} |
| 20 | + |
| 21 | +class MySeq(override val length: Int) extends collection.Seq[String] { |
| 22 | + def foo: Int = length // error |
| 23 | + |
| 24 | + def apply(v1: Int): String = ??? |
| 25 | + def iterator: Iterator[String] = ??? |
| 26 | +} |
| 27 | + |
| 28 | +class MyInspector extends Inspector { |
| 29 | + def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit = { |
| 30 | + import quotes.reflect.* |
| 31 | + val traverser = new TreeTraverser { |
| 32 | + override def traverseTree(tree: Tree)(owner: Symbol): Unit = { |
| 33 | + if (tree.isExpr) { |
| 34 | + try { |
| 35 | + tree.asExpr match { |
| 36 | + case '{ ($x: collection.Seq[t]).length } => |
| 37 | + super.traverseTree(tree)(owner) |
| 38 | + case _ => |
| 39 | + super.traverseTree(tree)(owner) |
| 40 | + } |
| 41 | + } catch { |
| 42 | + case e => |
| 43 | + report.error(s"unexpected error ${e}", tree.pos) |
| 44 | + throw e |
| 45 | + } |
| 46 | + } else { |
| 47 | + super.traverseTree(tree)(owner) |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + tastys.foreach{ tasty => |
| 52 | + traverser.traverseTree(tasty.ast)(tasty.ast.symbol) |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments