Closed
Description
area:ide
Compiler version
3.1.3-RC2 and later
Minimized code
val sourceDefinition = "object Definition { def x }"
val uriDefinition = new URI("file:///def")
driver.run(uriDefinition, sourceDefinition) // where driver: InteractiveDriver
given ctx: Context = driver.currentCtx
val pos = new SourcePosition(driver.openedFiles(uriDefinition), Spans.Span(sourceDefinition.indexOf("def x") + "def x".length))
val path = Interactive.pathTo(driver.openedTrees(uriDefinition), pos)
path.foreach(println)
Output
with 3.1.3-RC2
or later
Literal(Constant(null))
DefDef(x,List(),...)
Template(...)
TypeDef(...)
with 3.1.2
DefDef(x,List(),...)
Template(...)
TypeDef(...)
Expectation
Scala 3.1.3 should return the same result as Scala 3.1.2. There shouldn't be a Literal(Constant(null))
.
Additional context
This is a bit of a problem for Metals, for example, when Metals try to invoke advanced completion based on the path to the cursor position something like def |
(|
represents the cursor position).
As a workaround Metals ignore Literas(Constant(null))
.
https://github.com/scalameta/metals/blob/92d8d9ecdaead1a6db2a9ebb1a85500c22c4714d/mtags/src/main/scala-3/scala/meta/internal/pc/completions/Completions.scala#L136-L139