Skip to content
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

Interactive: fix contextOfPath for Template #12783

Merged
merged 1 commit into from
Feb 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -994,4 +994,33 @@ class CompletionTest {
("annotation", Module, "scala.annotation")
)
)
@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)
}
}