@@ -332,14 +332,20 @@ object Denotations {
332332 }
333333
334334 /** Handle merge conflict by throwing a `MergeError` exception */
335- private def mergeConflict (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type = {
335+ private def mergeConflict (tp1 : Type , tp2 : Type , that : Denotation )(implicit ctx : Context ): Type = {
336+ def showSymbol (sym : Symbol ): String = if (sym.exists) sym.showLocated else " [unknown]"
336337 def showType (tp : Type ) = tp match {
337338 case ClassInfo (_, cls, _, _, _) => cls.showLocated
338339 case bounds : TypeBounds => i " type bounds $bounds"
339340 case _ => tp.show
340341 }
341- if (true ) throw new MergeError (s " cannot merge ${showType(tp1)} with ${showType(tp2)}" , tp1, tp2)
342- else throw new Error (s " cannot merge ${showType(tp1)} with ${showType(tp2)}" ) // flip condition for debugging
342+ val msg =
343+ s """ cannot merge
344+ | ${showSymbol(this .symbol)} of type ${showType(tp1)} and
345+ | ${showSymbol(that.symbol)} of type ${showType(tp2)}
346+ """
347+ if (true ) throw new MergeError (msg, tp1, tp2)
348+ else throw new Error (msg) // flip condition for debugging
343349 }
344350
345351 /** Merge parameter names of lambda types. If names in corresponding positions match, keep them,
@@ -389,13 +395,13 @@ object Denotations {
389395 tp2 match {
390396 case tp2 : TypeBounds => if (safeIntersection) tp1 safe_& tp2 else tp1 & tp2
391397 case tp2 : ClassInfo if tp1 contains tp2 => tp2
392- case _ => mergeConflict(tp1, tp2)
398+ case _ => mergeConflict(tp1, tp2, that )
393399 }
394400 case tp1 : ClassInfo =>
395401 tp2 match {
396402 case tp2 : ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix & tp2.prefix)
397403 case tp2 : TypeBounds if tp2 contains tp1 => tp1
398- case _ => mergeConflict(tp1, tp2)
404+ case _ => mergeConflict(tp1, tp2, that )
399405 }
400406 case tp1 : MethodOrPoly =>
401407 tp2 match {
@@ -420,9 +426,9 @@ object Denotations {
420426 tp1.derivedLambdaType(
421427 mergeParamNames(tp1, tp2), tp1.paramInfos,
422428 infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
423- else mergeConflict(tp1, tp2)
429+ else mergeConflict(tp1, tp2, that )
424430 case _ =>
425- mergeConflict(tp1, tp2)
431+ mergeConflict(tp1, tp2, that )
426432 }
427433 case _ =>
428434 tp1 & tp2
@@ -523,7 +529,12 @@ object Denotations {
523529 try infoMeet(info1, info2)
524530 catch {
525531 case ex : MergeError =>
526- if (pre.widen.classSymbol.is(Scala2x ) || ctx.scala2Mode)
532+ // TODO: this picks one type over the other whereas it might be better
533+ // to return a MultiDenotation instead. But doing so would affect lots of
534+ // things, starting with the return type of this method.
535+ if (preferSym(sym2, sym1)) info2
536+ else if (preferSym(sym1, sym2)) info1
537+ else if (pre.widen.classSymbol.is(Scala2x ) || ctx.scala2Mode)
527538 info1 // follow Scala2 linearization -
528539 // compare with way merge is performed in SymDenotation#computeMembersNamed
529540 else
@@ -560,13 +571,13 @@ object Denotations {
560571 tp2 match {
561572 case tp2 : TypeBounds => tp1 | tp2
562573 case tp2 : ClassInfo if tp1 contains tp2 => tp1
563- case _ => mergeConflict(tp1, tp2)
574+ case _ => mergeConflict(tp1, tp2, that )
564575 }
565576 case tp1 : ClassInfo =>
566577 tp2 match {
567578 case tp2 : ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix | tp2.prefix)
568579 case tp2 : TypeBounds if tp2 contains tp1 => tp2
569- case _ => mergeConflict(tp1, tp2)
580+ case _ => mergeConflict(tp1, tp2, that )
570581 }
571582 case tp1 : MethodOrPoly =>
572583 tp2 match {
@@ -577,7 +588,7 @@ object Denotations {
577588 mergeParamNames(tp1, tp2), tp1.paramInfos,
578589 tp1.resultType | tp2.resultType.subst(tp2, tp1))
579590 case _ =>
580- mergeConflict(tp1, tp2)
591+ mergeConflict(tp1, tp2, that )
581592 }
582593 case _ =>
583594 tp1 | tp2
0 commit comments