Skip to content

IDE: Avoid exception when doing go-to-definition on something that doesn't exist #5963

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

Merged
merged 1 commit into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ class SymUtils(val self: Symbol) extends AnyVal {

/** Is symbol directly or indirectly owned by a term symbol? */
@tailrec final def isLocal(implicit ctx: Context): Boolean = {
val owner = self.owner
if (owner.isTerm) true
val owner = self.maybeOwner
if (!owner.exists) false
else if (owner.isTerm) true
else if (owner.is(Package)) false
else owner.isLocal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,15 @@ class DefinitionTest {
.definition(m17 to m18, List(m11 to m12))
.definition(m19 to m20, List(m13 to m14))
}

@Test def definitionDoesNotExist: Unit = withSources(
code"""object Foo {
| ${m1}unknown1${m2}
| ${m3}unknown2${m4}.${m5}unknown3${m6}
| Foo.${m7}unknown4${m8}
|}""")
.definition(m1 to m2, Nil)
.definition(m3 to m4, Nil)
.definition(m5 to m6, Nil)
.definition(m7 to m8, Nil)
}