Skip to content

Commit c3c09e3

Browse files
committed
WIP: precise unapply return
1 parent 6fce4ca commit c3c09e3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,6 @@ object desugar {
527527
// a reference to the class type bound by `cdef`, with type parameters coming from the constructor
528528
val classTypeRef = appliedRef(classTycon)
529529

530-
def applyResultTpt =
531-
if isEnumCase then
532-
classTypeRef
533-
else
534-
TypeTree()
535-
536530
// a reference to `enumClass`, with type parameters coming from the case constructor
537531
lazy val enumClassTypeRef =
538532
if (enumClass.typeParams.isEmpty)
@@ -611,7 +605,7 @@ object desugar {
611605
cpy.ValDef(vparam)(rhs = copyDefault(vparam)))
612606
val copyRestParamss = derivedVparamss.tail.nestedMap(vparam =>
613607
cpy.ValDef(vparam)(rhs = EmptyTree))
614-
DefDef(nme.copy, derivedTparams, copyFirstParams :: copyRestParamss, applyResultTpt, creatorExpr)
608+
DefDef(nme.copy, derivedTparams, copyFirstParams :: copyRestParamss, classTypeRef, creatorExpr)
615609
.withMods(Modifiers(Synthetic | constr1.mods.flags & copiedAccessFlags, constr1.mods.privateWithin)) :: Nil
616610
}
617611
}
@@ -704,7 +698,7 @@ object desugar {
704698
val appParamss =
705699
derivedVparamss.nestedZipWithConserve(constrVparamss)((ap, cp) =>
706700
ap.withMods(ap.mods | (cp.mods.flags & HasDefault)))
707-
DefDef(nme.apply, derivedTparams, appParamss, applyResultTpt, creatorExpr)
701+
DefDef(nme.apply, derivedTparams, appParamss, classTypeRef, creatorExpr)
708702
.withMods(appMods) :: Nil
709703
}
710704
val unapplyMeth = {
@@ -714,7 +708,9 @@ object desugar {
714708
val methName = if (hasRepeatedParam) nme.unapplySeq else nme.unapply
715709
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
716710
val unapplyRHS = if (arity == 0) Literal(Constant(true)) else Ident(unapplyParam.name)
717-
val unapplyResTp = if (arity == 0) Literal(Constant(true)) else applyResultTpt
711+
val unapplyResTp =
712+
if arity == 0 then Literal(Constant(true))
713+
else makeAndType(classTypeRef, SingletonTypeTree(Ident(unapplyParam.name)))
718714
DefDef(methName, derivedTparams, (unapplyParam :: Nil) :: Nil, unapplyResTp, unapplyRHS)
719715
.withMods(synthetic)
720716
}

0 commit comments

Comments
 (0)