question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Interactive.pathTo` contains `Literal(Constant(null))` as a head of path for incomplete program

See original GitHub issue

area:ide

Compiler version

3.1.3-RC2 and later

Minimized code

See: https://github.com/tanishiking/dotty-interactive-playground/blob/50ea5babab3d6d124b98597873af371765b97bf3/src/main/scala/Main.scala#L45-L64

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, May 28, 2022

this is what we did in our internal tooling that uses the compiler and it has been very handy!

Off-topic, but this is intriguing 😃, is this something you could share more information on?

More on-topic: I think it’s worth adding a comment to pathTo mentioning that it might return errorTermTree (but presumably only if ctx.reporter.errorsReported is true), and it seems like we could then close this issue.

1reaction
adampaulscommented, May 27, 2022

@tanishiking I think this is at least arguably working as intended? I recently made some changes (some of which @odersky largely rewrote) to add the errorTermTree in more places for incomplete parses. The motivation in those PRs (e.g. https://github.com/lampepfl/dotty/pull/14463) was to differentiate between e.g. foo(x,<EOF> and foo(x). Before the PR, these two had the same parse, but the PR changed it so that the former gives foo(x, Literal(Constant(null)).

I think Metals should expect to see the errorTermTree (Literal(Constant(null))) and ignore it? Note that I did not add errorTermTree, I just made it occur in more places. It’s possible some of my changes caused this particular change, but I’m not sure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build settings reference | Apple Developer Documentation
A detailed list of individual Xcode build settings that control or change the way a target is built.
Read more >
openresty/lua-nginx-module: Embed the Power of ... - GitHub
Name. ngx_http_lua_module - Embed the power of Lua into Nginx HTTP Servers. This module is a core component of OpenResty. If you are...
Read more >
Linter rules - Dart
Tip: Linter rules (sometimes called lints) can have false positives, and they don't all agree with each other. For example, some rules are...
Read more >
Language Support for Java(TM) by Red Hat
Absolute path to JDK home folder used to launch the Java Language Server. Requires VS Code restart. java.jdt.ls.lombokSupport.enabled : Whether to enable lombok ......
Read more >
SQL0000 - SQL0249 - IBM
You can process an application program source file containing embedded SQL statements and create a package in the database using the PRECOMPILE command....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found