Commit 361b5b2
committed
Fix #4498: Go to definition in lifted expressions
Consider the following snippet:
```
val lst = new A :: Nil
```
This is rewritten as:
```
val lst = {
val x$0 = new A
Nil.::(x$0)
}
```
During lifting, we need to assign positions to the trees. We were
assigning the position of `new A` in the original code to `x$0` in
`Nil.::(x$0)`, and the original position of `new A` to `val x$0 = new A`
with a zero-extent.
Still considering this snippet, this means that when trying to go to the
definition on `new A`, the IDE would think that the user tried to go to
the definition of `x$0`, because the IDE would look for the matching
tree by position.
This commit changes this so that the lifted definition
(`val x$0 = new A`) gets the position of the original expression, and
the reference gets a synthetic, zero-extent position. With this change,
the IDE correctly finds the right tree when selecting `new A` in the
original code.
Fixes #44981 parent d97bce0 commit 361b5b2
File tree
2 files changed
+9
-2
lines changed- compiler/src/dotty/tools/dotc/typer
- language-server/test/dotty/tools/languageserver
2 files changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
| 52 | + | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
0 commit comments