Skip to content

Commit 6c3d7cd

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

File tree

6 files changed

+82
-6
lines changed

6 files changed

+82
-6
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Symbols.scala

+16-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import dotty.tools.dotc.classpath.FileUtils.isScalaBinary
3232

3333
import scala.compiletime.uninitialized
3434
import dotty.tools.tasty.TastyVersion
35+
import dotty.tools.dotc.transform.CheckUnused.isSynthetic
36+
import dotty.tools.dotc.config.PathResolver.ppcp
3537

3638
object Symbols extends SymUtils {
3739

@@ -357,13 +359,25 @@ object Symbols extends SymUtils {
357359
targets.match
358360
case (tp: NamedType) :: _ => tp.symbol.sourceSymbol
359361
case _ => this
360-
else if (denot.is(Synthetic)) {
362+
else if denot.is(Synthetic) then
361363
val linked = denot.linkedClass
362364
if (linked.exists && !linked.is(Synthetic))
363365
linked
364366
else
365367
denot.owner.sourceSymbol
366-
}
368+
else if (
369+
denot.is(TypeParam) &&
370+
denot.maybeOwner.maybeOwner.isAllOf(EnumCase) &&
371+
denot.maybeOwner.isPrimaryConstructor
372+
) then
373+
val enclosingEnumCase = denot.maybeOwner.maybeOwner
374+
val caseTypeParam = enclosingEnumCase.typeParams.find(_.name == denot.name)
375+
if caseTypeParam.exists(_.is(Synthetic)) then
376+
val enumClass = enclosingEnumCase.info.firstParent.typeSymbol
377+
val sourceTypeParam = enumClass.typeParams.find(_.name == denot.name)
378+
sourceTypeParam.getOrElse(this)
379+
else
380+
caseTypeParam.getOrElse(this)
367381
else if (denot.isPrimaryConstructor)
368382
denot.owner.sourceSymbol
369383
else this

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

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ object Interactive {
144144

145145
( sym == tree.symbol
146146
|| sym.exists && sym == tree.symbol.sourceSymbol
147+
|| sym.exists && sym.sourceSymbol == tree.symbol
147148
|| !include.isEmpty && sym.name == tree.symbol.name && sym.maybeOwner != tree.symbol.maybeOwner
148149
&& ( include.isOverridden && overrides(sym, tree.symbol)
149150
|| include.isOverriding && overrides(tree.symbol, sym)

Diff for: 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
}

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

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

481+
@Test def `enum-class-type-param` =
482+
check(
483+
"""|
484+
|enum Options[<<AA>>]:
485+
| case Some(x: A@@A)
486+
| case None extends Options[Nothing]
487+
|""".stripMargin
488+
)
489+
490+
@Test def `enum-class-type-param-covariant` =
491+
check(
492+
"""|
493+
|enum Options[+<<AA>>]:
494+
| case Some(x: A@@A)
495+
| case None extends Options[Nothing]
496+
|""".stripMargin
497+
)
498+
499+
@Test def `enum-class-type-param-duplicate` =
500+
check(
501+
"""|
502+
|enum Testing[AA]:
503+
| case Some[<<AA>>](x: A@@A) extends Testing[AA]
504+
| case None extends Testing[Nothing]
505+
|""".stripMargin
506+
)
507+
481508
@Test def `derives-def` =
482509
check(
483510
"""|

Diff for: project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ object Build {
520520
"scala2-library-tasty"
521521
)
522522

523-
val enableBspAllProjects = false
523+
val enableBspAllProjects = true
524524

525525
// Settings used when compiling dotty with a non-bootstrapped dotty
526526
lazy val commonBootstrappedSettings = commonDottySettings ++ Seq(

Diff for: tasty/test/dotty/tools/tasty/BuildTastyVersionTest.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import TastyBuffer._
77

88
// Tests ensuring TASTY version emitted by compiler is matching expected TASTY version
99
class BuildTastyVersionTest {
10-
10+
1111
val CurrentTastyVersion = TastyVersion(TastyFormat.MajorVersion, TastyFormat.MinorVersion, TastyFormat.ExperimentalVersion)
12-
12+
1313
// Needs to be defined in build Test/envVars
1414
val ExpectedTastyVersionEnvVar = "EXPECTED_TASTY_VERSION"
15-
15+
1616
@Test def testBuildTastyVersion(): Unit = {
1717
val expectedVersion = sys.env.get(ExpectedTastyVersionEnvVar)
1818
.getOrElse(fail(s"Env variable $ExpectedTastyVersionEnvVar not defined"))

0 commit comments

Comments
 (0)