Skip to content

Add enum type param support in sourceSymbol #18603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,25 @@ object Symbols extends SymUtils {
targets.match
case (tp: NamedType) :: _ => tp.symbol.sourceSymbol
case _ => this
else if (denot.is(Synthetic)) {
else if denot.is(Synthetic) then
val linked = denot.linkedClass
if (linked.exists && !linked.is(Synthetic))
linked
else
denot.owner.sourceSymbol
}
else if (
denot.is(TypeParam) &&
denot.maybeOwner.maybeOwner.isAllOf(EnumCase) &&
denot.maybeOwner.isPrimaryConstructor
) then
val enclosingEnumCase = denot.maybeOwner.maybeOwner
val caseTypeParam = enclosingEnumCase.typeParams.find(_.name == denot.name)
if caseTypeParam.exists(_.is(Synthetic)) then
val enumClass = enclosingEnumCase.info.firstParent.typeSymbol
val sourceTypeParam = enumClass.typeParams.find(_.name == denot.name)
sourceTypeParam.getOrElse(this)
else
caseTypeParam.getOrElse(this)
else if (denot.isPrimaryConstructor)
denot.owner.sourceSymbol
else this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ object Interactive {

( sym == tree.symbol
|| sym.exists && sym == tree.symbol.sourceSymbol
|| sym.exists && sym.sourceSymbol == tree.symbol
|| !include.isEmpty && sym.name == tree.symbol.name && sym.maybeOwner != tree.symbol.maybeOwner
&& ( include.isOverridden && overrides(sym, tree.symbol)
|| include.isOverriding && overrides(tree.symbol, sym)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,38 @@ class DefinitionTest {
.definition(m3 to m4, Nil)
.definition(m5 to m6, Nil)
.definition(m7 to m8, Nil)

@Test def typeParam: Unit = {
code"""|class Foo[${m1}T${m2}]:
| def test: ${m3}T${m4}"""
.definition(m3 to m4, List(m1 to m2))
}

@Test def enumTypeParam: Unit = {
code"""|enum Test[${m1}T${m2}]:
| case EnumCase(value: ${m3}T${m4})"""
.definition(m3 to m4, List(m1 to m2))
}

@Test def extMethodTypeParam: Unit = {
code"""extension [${m1}T${m2}](string: String) def xxxx(y: ${m3}T${m4}) = ???"""
.definition(m3 to m4, List(m1 to m2))
}

@Test def typeParamCovariant: Unit = {
code"""|class Foo[+${m1}T${m2}]:
| def test: ${m3}T${m4}"""
.definition(m3 to m4, List(m1 to m2))
}

@Test def enumTypeParamCovariant: Unit = {
code"""|enum Test[+${m1}T${m2}]:
| case EnumCase(value: ${m3}T${m4})"""
.definition(m3 to m4, List(m1 to m2))
}

@Test def extMethodTypeParamCovariant: Unit = {
code"""extension [+${m1}T${m2}](string: String) def xxxx(y: ${m3}T${m4}) = ???"""
.definition(m3 to m4, List(m1 to m2))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,33 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
|""".stripMargin
)

@Test def `enum-class-type-param` =
check(
"""|
|enum Options[<<AA>>]:
| case Some(x: A@@A)
| case None extends Options[Nothing]
|""".stripMargin
)

@Test def `enum-class-type-param-covariant` =
check(
"""|
|enum Options[+<<AA>>]:
| case Some(x: A@@A)
| case None extends Options[Nothing]
|""".stripMargin
)

@Test def `enum-class-type-param-duplicate` =
check(
"""|
|enum Testing[AA]:
| case Some[<<AA>>](x: A@@A) extends Testing[AA]
| case None extends Testing[Nothing]
|""".stripMargin
)

@Test def `derives-def` =
check(
"""|
Expand Down
Loading