Skip to content

Commit

Permalink
Interactive: fix contextOfPath for Template
Browse files Browse the repository at this point in the history
  • Loading branch information
dos65 committed Jul 16, 2021
1 parent 20e2b95 commit 0ff94b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Expand Up @@ -293,8 +293,10 @@ object Interactive {
// in subsequent parameter sections
localCtx
case tree: MemberDef =>
assert(tree.symbol.exists)
outer.localContext(tree, tree.symbol)
if (tree.symbol.exists)
outer.localContext(tree, tree.symbol)
else
outer
case tree @ Block(stats, expr) =>
val localCtx = outer.fresh.setNewScope
stats.foreach {
Expand All @@ -310,7 +312,7 @@ object Interactive {
}
localCtx
case tree @ Template(constr, parents, self, _) =>
if ((constr :: self :: parents).contains(nested)) ctx
if ((constr :: self :: parents).contains(nested)) outer
else contextOfStat(tree.body, nested, tree.symbol, outer.inClassContext(self.symbol))
case _ =>
outer
Expand Down
Expand Up @@ -842,4 +842,34 @@ class CompletionTest {
|object Main { "abc".xx${m1} }""".withSource
.completion(m1, Set())
}

@Test def completeTemplateConstrArgType: Unit = {
val expected = Set(
("Future", Class, "scala.concurrent.Future"),
("Future", Module, "scala.concurrent.Future")
)
code"""import scala.concurrent.Future
|class Foo(x: Fut${m1})""".withSource
.completion(m1, expected)
}

@Test def completeTemplateParents: Unit = {
val expected = Set(
("Future", Class, "scala.concurrent.Future"),
("Future", Module, "scala.concurrent.Future")
)
code"""import scala.concurrent.Future
|class Foo extends Futu${m1}""".withSource
.completion(m1, expected)
}

@Test def completeTemplateSelfType: Unit = {
val expected = Set(
("Future", Class, "scala.concurrent.Future"),
("Future", Module, "scala.concurrent.Future")
)
code"""import scala.concurrent.Future
|class Foo[A]{ self: Futu${m1} => }""".withSource
.completion(m1, expected)
}
}

0 comments on commit 0ff94b2

Please sign in to comment.