Skip to content

Commit 7aa17c5

Browse files
rochalaKordyjan
authored andcommitted
Adjust owner in Interactive.contextOfPath causing crash in ImplicitSearch (#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
1 parent a086db7 commit 7aa17c5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/interactive/Interactive.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ object Interactive {
297297
else
298298
outer
299299
case tree @ Block(stats, expr) =>
300-
val localCtx = outer.fresh.setNewScope
300+
val localCtx = outer.localContext(tree, outer.owner).setNewScope
301301
stats.foreach {
302302
case stat: MemberDef => localCtx.enter(stat.symbol)
303303
case _ =>
304304
}
305-
contextOfStat(stats, nested, ctx.owner, localCtx)
305+
contextOfStat(stats, nested, localCtx.owner, localCtx)
306306
case tree @ CaseDef(pat, _, _) =>
307-
val localCtx = outer.fresh.setNewScope
307+
val localCtx = outer.localContext(tree, outer.owner).setNewScope
308308
pat.foreachSubTree {
309309
case bind: Bind => localCtx.enter(bind.symbol)
310310
case _ =>

Diff for: language-server/test/dotty/tools/languageserver/CompletionTest.scala

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ class CompletionTest {
3535
.completion(("Conversion", Class, "Conversion"))
3636
}
3737

38+
@Test def implicitSearchCrash: Unit =
39+
code"""
40+
|object Test:
41+
| trait Foo:
42+
| def test(): String
43+
| given Int = ???
44+
| given (using ev: Int): Conversion[String, Foo] = ???
45+
|
46+
| val test = {
47+
| "".tes$m1
48+
| 1
49+
| }"""
50+
.completion(("test", Method, "(): String"))
51+
3852
@Test def completionFromScalaPackageObject: Unit = {
3953
code"class Foo { val foo: BigD${m1} }"
4054
.completion(

0 commit comments

Comments
 (0)