@@ -32,8 +32,8 @@ object CheckRealizable {
3232 class HasProblemBaseArg (typ : Type , argBounds : TypeBounds )(using Context )
3333 extends Realizability (i " has a base type $typ with possibly conflicting parameter bounds ${argBounds.lo} <: ... <: ${argBounds.hi}" )
3434
35- class HasProblemBase (base1 : Type , base2 : Type )(using Context )
36- extends Realizability (i " has conflicting base types $base1 and $base2" )
35+ class HasProblemBase (base1 : Type , base2 : Type , argStr : String )(using Context )
36+ extends Realizability (i " has conflicting base type ${argStr} s $base1 and $base2" )
3737
3838 class HasProblemField (fld : SingleDenotation , problem : Realizability )(using Context )
3939 extends Realizability (i " has a member $fld which is not a legal path \n since ${fld.symbol.name}: ${fld.info}${problem.msg}" )
@@ -167,17 +167,30 @@ class CheckRealizable(using Context) {
167167 new HasProblemBounds (name, mbr.info)
168168 }
169169
170- def baseTypeProblems (base : Type ) = base match {
171- case AndType (base1, base2) =>
172- new HasProblemBase (base1, base2) :: Nil
173- case base =>
174- base.argInfos.collect {
175- case bounds @ TypeBounds (lo, hi) if ! (lo <:< hi) =>
176- new HasProblemBaseArg (base, bounds)
170+ def baseTypeProblems (base : Type , argStr : String ): List [Realizability ] = base match {
171+ case base : AndType =>
172+ def factors (tp : Type ): List [Type ] = tp match
173+ case AndType (tp1, tp2) => factors(tp1) ++ factors(tp2)
174+ case _ => tp :: Nil
175+ for case AndType (base1, base2) <-
176+ factors(base).groupBy(_.classSymbol).values.map(_.reduce(_ & _)).toList
177+ // try to merge factors with common class symbols
178+ // if we cannot, it's a conflict
179+ yield HasProblemBase (base1, base2, argStr)
180+ case base : AppliedType =>
181+ base.argInfos.lazyZip(base.tycon.typeParams).flatMap { (arg, tparam) =>
182+ arg match
183+ case bounds @ TypeBounds (lo, hi) if ! (lo <:< hi) =>
184+ new HasProblemBaseArg (base, bounds) :: Nil
185+ case arg if tparam.paramVarianceSign == 0 =>
186+ baseTypeProblems(arg, " argument" )
187+ case _ =>
188+ Nil
177189 }
190+ case _ => Nil
178191 }
179192 val baseProblems =
180- tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems)
193+ tp.baseClasses.map(_.baseTypeOf(tp)).flatMap(baseTypeProblems(_, " " ) )
181194
182195 baseProblems.foldLeft(
183196 refinementProblems.foldLeft(
0 commit comments