Skip to content

Commit

Permalink
Add type parameters derived from enum to default param getters of enu…
Browse files Browse the repository at this point in the history
…m cases
  • Loading branch information
kasiaMarek committed Dec 12, 2024
1 parent 5b3d82a commit 6b9f9f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 12 additions & 7 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -694,15 +694,15 @@ object desugar {
val originalTparams = constr1.leadingTypeParams
val originalVparamss = asTermOnly(constr1.trailingParamss)
lazy val derivedEnumParams = enumClass.typeParams.map(derivedTypeParamWithVariance)
val impliedTparams =
if (isEnumCase) {
val enumTParams =
if isEnumCase then
val tparamReferenced = typeParamIsReferenced(
enumClass.typeParams, originalTparams, originalVparamss, parents)
if (originalTparams.isEmpty && (parents.isEmpty || tparamReferenced))
enumClass.typeParams, originalTparams, originalVparamss, parents)
if originalTparams.isEmpty && (parents.isEmpty || tparamReferenced) then
derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal))
else originalTparams
}
else originalTparams
else Nil
else Nil
val impliedTparams = enumTParams ++ originalTparams

if mods.is(Trait) then
for vparams <- originalVparamss; vparam <- vparams do
Expand Down Expand Up @@ -735,6 +735,11 @@ object desugar {
derived.withAnnotations(Nil)

val constr = cpy.DefDef(constr1)(paramss = joinParams(constrTparams, constrVparamss))
if enumTParams.nonEmpty then
defaultGetters = defaultGetters.map:
case ddef: DefDef =>
val tParams = enumTParams.map(tparam => toMethParam(tparam, KeepAnnotations.All))
cpy.DefDef(ddef)(paramss = joinParams(tParams, ddef.trailingParamss))

val (normalizedBody, enumCases, enumCompanionRef) = {
// Add constructor type parameters and evidence implicit parameters
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i22137.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum Parser[+Value]:
case Success(value: Value, issues: Seq[Failure] = Seq.empty) extends Parser[Value]
case Failure(exception: Throwable) extends Parser[Nothing]

val v = Parser.Success(1)

0 comments on commit 6b9f9f7

Please sign in to comment.