Skip to content

Commit 3f5d15d

Browse files
oderskyDarkDimius
authored andcommitted
Fix desugaring of refined types with "&"-parent.
need to generate more than one parent class.
1 parent 8cf176a commit 3f5d15d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,18 +864,19 @@ object desugar {
864864
* @param parentType The type of `parent`
865865
*/
866866
def refinedTypeToClass(parent: tpd.Tree, refinements: List[Tree])(implicit ctx: Context): TypeDef = {
867-
def stripToCore(tp: Type): Type = tp match {
868-
case tp: RefinedType if tp.argInfos.nonEmpty => tp // parameterized class type
869-
case tp: TypeRef if tp.symbol.isClass => tp // monomorphic class type
867+
def stripToCore(tp: Type): List[Type] = tp match {
868+
case tp: RefinedType if tp.argInfos.nonEmpty => tp :: Nil // parameterized class type
869+
case tp: TypeRef if tp.symbol.isClass => tp :: Nil // monomorphic class type
870870
case tp: TypeProxy => stripToCore(tp.underlying)
871-
case _ => defn.AnyType
871+
case AndType(tp1, tp2) => stripToCore(tp1) ::: stripToCore(tp2)
872+
case _ => defn.AnyType :: Nil
872873
}
873-
val parentCore = stripToCore(parent.tpe)
874+
val parentCores = stripToCore(parent.tpe)
874875
val untpdParent = TypedSplice(parent)
875-
val (classParent, self) =
876-
if (parent.tpe eq parentCore) (untpdParent, EmptyValDef)
877-
else (TypeTree(parentCore), ValDef(nme.WILDCARD, untpdParent, EmptyTree))
878-
val impl = Template(emptyConstructor, classParent :: Nil, self, refinements)
876+
val (classParents, self) =
877+
if (parentCores.length == 1 && (parent.tpe eq parentCores.head)) (untpdParent :: Nil, EmptyValDef)
878+
else (parentCores map TypeTree, ValDef(nme.WILDCARD, untpdParent, EmptyTree))
879+
val impl = Template(emptyConstructor, classParents, self, refinements)
879880
TypeDef(tpnme.REFINE_CLASS, impl).withFlags(Trait)
880881
}
881882

0 commit comments

Comments
 (0)