Skip to content

Commit daf4ce9

Browse files
authored
Merge pull request #5963 from dotty-staging/fix/gotodef-exception
IDE: Avoid exception when doing go-to-definition on something that doesn't exist
2 parents ab1da64 + 7c91e49 commit daf4ce9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ class SymUtils(val self: Symbol) extends AnyVal {
150150

151151
/** Is symbol directly or indirectly owned by a term symbol? */
152152
@tailrec final def isLocal(implicit ctx: Context): Boolean = {
153-
val owner = self.owner
154-
if (owner.isTerm) true
153+
val owner = self.maybeOwner
154+
if (!owner.exists) false
155+
else if (owner.isTerm) true
155156
else if (owner.is(Package)) false
156157
else owner.isLocal
157158
}

language-server/test/dotty/tools/languageserver/DefinitionTest.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,15 @@ class DefinitionTest {
367367
.definition(m17 to m18, List(m11 to m12))
368368
.definition(m19 to m20, List(m13 to m14))
369369
}
370+
371+
@Test def definitionDoesNotExist: Unit = withSources(
372+
code"""object Foo {
373+
| ${m1}unknown1${m2}
374+
| ${m3}unknown2${m4}.${m5}unknown3${m6}
375+
| Foo.${m7}unknown4${m8}
376+
|}""")
377+
.definition(m1 to m2, Nil)
378+
.definition(m3 to m4, Nil)
379+
.definition(m5 to m6, Nil)
380+
.definition(m7 to m8, Nil)
370381
}

0 commit comments

Comments
 (0)