Skip to content

Commit 0ff94b2

Browse files
committed
Interactive: fix contextOfPath for Template
1 parent 20e2b95 commit 0ff94b2

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ object Interactive {
293293
// in subsequent parameter sections
294294
localCtx
295295
case tree: MemberDef =>
296-
assert(tree.symbol.exists)
297-
outer.localContext(tree, tree.symbol)
296+
if (tree.symbol.exists)
297+
outer.localContext(tree, tree.symbol)
298+
else
299+
outer
298300
case tree @ Block(stats, expr) =>
299301
val localCtx = outer.fresh.setNewScope
300302
stats.foreach {
@@ -310,7 +312,7 @@ object Interactive {
310312
}
311313
localCtx
312314
case tree @ Template(constr, parents, self, _) =>
313-
if ((constr :: self :: parents).contains(nested)) ctx
315+
if ((constr :: self :: parents).contains(nested)) outer
314316
else contextOfStat(tree.body, nested, tree.symbol, outer.inClassContext(self.symbol))
315317
case _ =>
316318
outer

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,4 +842,34 @@ class CompletionTest {
842842
|object Main { "abc".xx${m1} }""".withSource
843843
.completion(m1, Set())
844844
}
845+
846+
@Test def completeTemplateConstrArgType: Unit = {
847+
val expected = Set(
848+
("Future", Class, "scala.concurrent.Future"),
849+
("Future", Module, "scala.concurrent.Future")
850+
)
851+
code"""import scala.concurrent.Future
852+
|class Foo(x: Fut${m1})""".withSource
853+
.completion(m1, expected)
854+
}
855+
856+
@Test def completeTemplateParents: Unit = {
857+
val expected = Set(
858+
("Future", Class, "scala.concurrent.Future"),
859+
("Future", Module, "scala.concurrent.Future")
860+
)
861+
code"""import scala.concurrent.Future
862+
|class Foo extends Futu${m1}""".withSource
863+
.completion(m1, expected)
864+
}
865+
866+
@Test def completeTemplateSelfType: Unit = {
867+
val expected = Set(
868+
("Future", Class, "scala.concurrent.Future"),
869+
("Future", Module, "scala.concurrent.Future")
870+
)
871+
code"""import scala.concurrent.Future
872+
|class Foo[A]{ self: Futu${m1} => }""".withSource
873+
.completion(m1, expected)
874+
}
845875
}

0 commit comments

Comments
 (0)