Skip to content

Commit

Permalink
Adjust owner in Interactive.contextOfPath causing crash in `Implici…
Browse files Browse the repository at this point in the history
…tSearch` (scala#19875)

`Interactive` provided us with the method `contextOfPath` which should
return enclosing ctx for given position. It was working fine until given
loop detection was improved some time ago.

It started crashing as the context owner was set to original context
owner, instead of the real owner. This PR changes this and sets context
to its outer context owner.

Fixes scalameta/metals#6193
  • Loading branch information
rochala authored and Kordyjan committed Mar 12, 2024
1 parent a086db7 commit 7aa17c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ object Interactive {
else
outer
case tree @ Block(stats, expr) =>
val localCtx = outer.fresh.setNewScope
val localCtx = outer.localContext(tree, outer.owner).setNewScope
stats.foreach {
case stat: MemberDef => localCtx.enter(stat.symbol)
case _ =>
}
contextOfStat(stats, nested, ctx.owner, localCtx)
contextOfStat(stats, nested, localCtx.owner, localCtx)
case tree @ CaseDef(pat, _, _) =>
val localCtx = outer.fresh.setNewScope
val localCtx = outer.localContext(tree, outer.owner).setNewScope
pat.foreachSubTree {
case bind: Bind => localCtx.enter(bind.symbol)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ class CompletionTest {
.completion(("Conversion", Class, "Conversion"))
}

@Test def implicitSearchCrash: Unit =
code"""
|object Test:
| trait Foo:
| def test(): String
| given Int = ???
| given (using ev: Int): Conversion[String, Foo] = ???
|
| val test = {
| "".tes$m1
| 1
| }"""
.completion(("test", Method, "(): String"))

@Test def completionFromScalaPackageObject: Unit = {
code"class Foo { val foo: BigD${m1} }"
.completion(
Expand Down

0 comments on commit 7aa17c5

Please sign in to comment.