Skip to content

Commit 4b50294

Browse files
authored
Merge pull request #5410 from dotty-staging/fix/ide-anon-classes
Give point position to synthetic class parent
2 parents 4385494 + 658ea77 commit 4b50294

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ class Typer extends Namer
16751675
/** Ensure that first parent tree refers to a real class. */
16761676
def ensureFirstTreeIsClass(parents: List[Tree], pos: Position)(implicit ctx: Context): List[Tree] = parents match {
16771677
case p :: ps if p.tpe.classSymbol.isRealClass => parents
1678-
case _ => TypeTree(ensureFirstIsClass(parents.tpes, pos).head).withPos(pos) :: parents
1678+
case _ => TypeTree(ensureFirstIsClass(parents.tpes, pos).head).withPos(pos.focus) :: parents
16791679
}
16801680

16811681
/** If this is a real class, make sure its first parent is a

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,34 @@ class DefinitionTest {
219219
).definition(m3 to m4, List(m1 to m2))
220220
}
221221

222+
@Test def definitionAnonClassTrait: Unit = {
223+
code"""trait ${m1}Foo${m2} { val x = 0 }
224+
class C {
225+
def foo = new ${m3}Foo${m4} {}
226+
}""".withSource
227+
.definition(m1 to m2, List(m1 to m2))
228+
.definition(m3 to m4, List(m1 to m2))
229+
}
230+
231+
@Test def definitionAnonClassClass: Unit = {
232+
code"""abstract class ${m1}Foo${m2} { val x = 0 }
233+
class C {
234+
def foo = new ${m3}Foo${m4} {}
235+
}""".withSource
236+
.definition(m1 to m2, List(m1 to m2))
237+
.definition(m3 to m4, List(m1 to m2))
238+
}
239+
240+
@Test def definitionAnonClassClassTrait: Unit = {
241+
code"""abstract class ${m1}Foo${m2}
242+
trait ${m3}Bar${m4}
243+
class C {
244+
def foo = new ${m5}Foo${m6} with ${m7}Bar${m8} {}
245+
}""".withSource
246+
.definition(m1 to m2, List(m1 to m2))
247+
.definition(m3 to m4, List(m3 to m4))
248+
.definition(m5 to m6, List(m1 to m2))
249+
.definition(m7 to m8, List(m3 to m4))
250+
}
251+
222252
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@ class ReferencesTest {
4848
.references(m7 to m8, List(m7 to m8), withDecl = false)
4949
}
5050

51+
@Test def anonClassTrait: Unit = {
52+
code"""trait ${m1}Foo${m2}
53+
object O {
54+
val foo = new ${m3}Foo${m4} {}
55+
}""".withSource
56+
.references(m1 to m2, List(m1 to m2, m3 to m4), withDecl = true)
57+
.references(m1 to m2, List(m3 to m4), withDecl = false)
58+
.references(m3 to m4, List(m1 to m2, m3 to m4), withDecl = true)
59+
.references(m3 to m4, List(m3 to m4), withDecl = false)
60+
}
61+
5162
}

0 commit comments

Comments
 (0)