Skip to content

Interactive.pathTo shows ImportType for repeated enum case. #11683

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

Closed
tgodzik opened this issue Mar 10, 2021 · 2 comments · Fixed by #14498
Closed

Interactive.pathTo shows ImportType for repeated enum case. #11683

tgodzik opened this issue Mar 10, 2021 · 2 comments · Fixed by #14498

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Mar 10, 2021

Minimized code

Running:

val pos = sourcePosition(driver, params, uri)
val trees = driver.openedTrees(uri)
val path = Interactive.pathTo(trees, pos)
val tp = Interactive.enclosingType(trees, pos)
val tpw = tp.widenTermRefExpr

on

object SimpleEnum:
  enum Color:
    case Re@@d, Green, Blue

will produce type tree:

val tpw = ImportType(Ident(Color))

Expectation

We should get a valid type representing the Color enum.

What is weird is that Interactive.pathTo gives us:

path.head == Import(Ident(Color),List(ImportSelector(Ident(Red),EmptyTree,EmptyTree), ImportSelector(Ident(Green),EmptyTree,EmptyTree), ImportSelector(Ident(Blue),EmptyTree,EmptyTree)))

while there are no actual imports.

@bishabosha
Copy link
Member

bishabosha commented Mar 10, 2021

This may be because the first statement of an enum class template in the AST is an import statement of the cases, (its synthetic) which is probably overlapping the span for the actual cases.
https://github.com/lampepfl/dotty/blob/2961f69fe2805d8901103496f588d976f212d8ac/compiler/src/dotty/tools/dotc/ast/Desugar.scala#L521

@smarter
Copy link
Member

smarter commented Mar 10, 2021

You should be able to set a zero-extent span to that tree so pathTo skips over it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants