Skip to content

Commit 898a040

Browse files
rochalatgodzik
authored andcommitted
Add enum type param support in sourceSymbol
1 parent a25fe5e commit 898a040

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

+9
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ object Symbols extends SymUtils {
366366
}
367367
else if (denot.isPrimaryConstructor)
368368
denot.owner.sourceSymbol
369+
else if (
370+
denot.is(TypeParam) &&
371+
denot.maybeOwner.maybeOwner.isAllOf(EnumCase) &&
372+
denot.maybeOwner.isPrimaryConstructor
373+
) then
374+
val enclosingEnumCase = denot.maybeOwner.maybeOwner
375+
val enumClass = enclosingEnumCase.maybeOwner.linkedClass
376+
val sourceTypeParam = enumClass.typeParams.find(_.name == denot.name)
377+
sourceTypeParam.getOrElse(this)
369378
else this
370379

371380
/** The position of this symbol, or NoSpan if the symbol was not loaded

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

+34
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,38 @@ class DefinitionTest {
378378
.definition(m3 to m4, Nil)
379379
.definition(m5 to m6, Nil)
380380
.definition(m7 to m8, Nil)
381+
382+
@Test def typeParam: Unit = {
383+
code"""|class Foo[${m1}T${m2}]:
384+
| def test: ${m3}T${m4}"""
385+
.definition(m3 to m4, List(m1 to m2))
386+
}
387+
388+
@Test def enumTypeParam: Unit = {
389+
code"""|enum Test[${m1}T${m2}]:
390+
| case EnumCase(value: ${m3}T${m4})"""
391+
.definition(m3 to m4, List(m1 to m2))
392+
}
393+
394+
@Test def extMethodTypeParam: Unit = {
395+
code"""extension [${m1}T${m2}](string: String) def xxxx(y: ${m3}T${m4}) = ???"""
396+
.definition(m3 to m4, List(m1 to m2))
397+
}
398+
399+
@Test def typeParamCovariant: Unit = {
400+
code"""|class Foo[+${m1}T${m2}]:
401+
| def test: ${m3}T${m4}"""
402+
.definition(m3 to m4, List(m1 to m2))
403+
}
404+
405+
@Test def enumTypeParamCovariant: Unit = {
406+
code"""|enum Test[+${m1}T${m2}]:
407+
| case EnumCase(value: ${m3}T${m4})"""
408+
.definition(m3 to m4, List(m1 to m2))
409+
}
410+
411+
@Test def extMethodTypeParamCovariant: Unit = {
412+
code"""extension [+${m1}T${m2}](string: String) def xxxx(y: ${m3}T${m4}) = ???"""
413+
.definition(m3 to m4, List(m1 to m2))
414+
}
381415
}

presentation-compiler/test/dotty/tools/pc/tests/definition/PcDefinitionSuite.scala

+18
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,24 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
478478
|""".stripMargin
479479
)
480480

481+
@Test def `enum-class-type-param` =
482+
check(
483+
"""|
484+
|enum Option[<<AA>>]
485+
| case Some(x: A@@A)
486+
| case None
487+
|""".stripMargin
488+
)
489+
490+
@Test def `enum-class-type-param-covariant` =
491+
check(
492+
"""|
493+
|enum Option[+<<AA>>]
494+
| case Some(x: A@@A)
495+
| case None
496+
|""".stripMargin
497+
)
498+
481499
@Test def `derives-def` =
482500
check(
483501
"""|

0 commit comments

Comments
 (0)