-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Getting Position of Tree fails execution #13352
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
Comments
Please try sticking to the issue format and providing a reproducing method with minimized code. |
How can this be reproduced? |
Sorry for not responding, I was on vacation. Here is the snippet: import scala.quoted.*
import scala.tasty.inspector.*
class MyInspector extends Inspector:
override def inspect(using q: Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
import q.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)
}
def list_urls(cl: ClassLoader): Array[java.net.URL] = cl match {
case null => Array()
case u: java.net.URLClassLoader => u.getURLs() ++ list_urls(cl.getParent)
case _ => list_urls(cl.getParent)
}
@main def main =
val urls = list_urls(getClass.getClassLoader).distinct
val inspector = new MyInspector
TastyInspector.inspectAllTastyFiles(Nil, urls.map(x => java.nio.file.Paths.get(x.toURI).toString).toList, Nil)(inspector) It is not that simple because we need to get some tasties to run them on, but this should get the classpath and run inspector on top of that. The crucial part is accessing |
@BarkingBad could you try to make it a test in |
Ok, could reproduce it with 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("CanEqual"))
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)
}
import annotation.implicitNotFound
import scala.collection.{Seq, Set}
/** A marker trait indicating that values of type `L` can be compared to values of type `R`. */
@implicitNotFound("Values of types ${L} and ${R} cannot be compared with == or !=")
sealed trait CanEqual[-L, -R]
/** Companion object containing a few universally known `CanEqual` instances.
* CanEqual instances involving primitive types or the Null type are handled directly in
* the compiler (see Implicits.synthesizedCanEqual), so they are not included here.
*/
object CanEqual {
/** A universal `CanEqual` instance. */
object derived extends CanEqual[Any, Any]
/** A fall-back instance to compare values of any types.
* Even though this method is not declared as given, the compiler will
* synthesize implicit arguments as solutions to `CanEqual[T, U]` queries if
* the rules of multiversal equality require it.
*/
def canEqualAny[L, R]: CanEqual[L, R] = derived
// Instances of `CanEqual` for common Java types
given canEqualNumber: CanEqual[Number, Number] = derived
given canEqualString: CanEqual[String, String] = derived
// The next 6 definitions can go into the companion objects of their corresponding
// classes. For now they are here in order not to have to touch the
// source code of these classes
given canEqualSeqs[T, U](using eq: CanEqual[T, U]): CanEqual[Seq[T], Seq[U]] = derived
given canEqualSeq[T](using eq: CanEqual[T, T]): CanEqual[Seq[T], Seq[T]] = derived // for `case Nil` in pattern matching
given canEqualSet[T, U](using eq: CanEqual[T, U]): CanEqual[Set[T], Set[U]] = derived
given canEqualOptions[T, U](using eq: CanEqual[T, U]): CanEqual[Option[T], Option[U]] = derived
given canEqualOption[T](using eq: CanEqual[T, T]): CanEqual[Option[T], Option[T]] = derived // for `case None` in pattern matching
given canEqualEither[L1, R1, L2, R2](
using eqL: CanEqual[L1, L2], eqR: CanEqual[R1, R2]
): CanEqual[Either[L1, R1], Either[L2, R2]] = derived
} |
Minimized to 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) =
println(tree)
println(" ")
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] |
I was about to move it to the |
Compiler version
3.1.0-RC1-bin-20210820-68044a6-NIGHTLY
When using
traverseTree
from QuotesTreeTraverser
trait I check the position of each tree I visit. For some reason accessing thepos
property, the execution fails. The stacktrace is leading to the assertion of the Span existence. The stacktrace is as follow:Stacktrace
The trees that were accessed in the traverser callback that cause failure
Failing trees
There used to be the
exists
function inPosition
to check whether theSpan
exists but IIRC was removed because accessingpos
should be safe now. I can provide a sample repo if necessary.The text was updated successfully, but these errors were encountered: