@@ -332,14 +332,20 @@ object Denotations {
332
332
}
333
333
334
334
/** 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]"
336
337
def showType (tp : Type ) = tp match {
337
338
case ClassInfo (_, cls, _, _, _) => cls.showLocated
338
339
case bounds : TypeBounds => i " type bounds $bounds"
339
340
case _ => tp.show
340
341
}
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
343
349
}
344
350
345
351
/** Merge parameter names of lambda types. If names in corresponding positions match, keep them,
@@ -389,13 +395,13 @@ object Denotations {
389
395
tp2 match {
390
396
case tp2 : TypeBounds => if (safeIntersection) tp1 safe_& tp2 else tp1 & tp2
391
397
case tp2 : ClassInfo if tp1 contains tp2 => tp2
392
- case _ => mergeConflict(tp1, tp2)
398
+ case _ => mergeConflict(tp1, tp2, that )
393
399
}
394
400
case tp1 : ClassInfo =>
395
401
tp2 match {
396
402
case tp2 : ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix & tp2.prefix)
397
403
case tp2 : TypeBounds if tp2 contains tp1 => tp1
398
- case _ => mergeConflict(tp1, tp2)
404
+ case _ => mergeConflict(tp1, tp2, that )
399
405
}
400
406
case tp1 : MethodOrPoly =>
401
407
tp2 match {
@@ -420,9 +426,9 @@ object Denotations {
420
426
tp1.derivedLambdaType(
421
427
mergeParamNames(tp1, tp2), tp1.paramInfos,
422
428
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
423
- else mergeConflict(tp1, tp2)
429
+ else mergeConflict(tp1, tp2, that )
424
430
case _ =>
425
- mergeConflict(tp1, tp2)
431
+ mergeConflict(tp1, tp2, that )
426
432
}
427
433
case _ =>
428
434
tp1 & tp2
@@ -523,7 +529,9 @@ object Denotations {
523
529
try infoMeet(info1, info2)
524
530
catch {
525
531
case ex : MergeError =>
526
- if (pre.widen.classSymbol.is(Scala2x ) || ctx.scala2Mode)
532
+ if (preferSym(sym2, sym1)) info2
533
+ else if (preferSym(sym1, sym2)) info1
534
+ else if (pre.widen.classSymbol.is(Scala2x ) || ctx.scala2Mode)
527
535
info1 // follow Scala2 linearization -
528
536
// compare with way merge is performed in SymDenotation#computeMembersNamed
529
537
else
@@ -560,13 +568,13 @@ object Denotations {
560
568
tp2 match {
561
569
case tp2 : TypeBounds => tp1 | tp2
562
570
case tp2 : ClassInfo if tp1 contains tp2 => tp1
563
- case _ => mergeConflict(tp1, tp2)
571
+ case _ => mergeConflict(tp1, tp2, that )
564
572
}
565
573
case tp1 : ClassInfo =>
566
574
tp2 match {
567
575
case tp2 : ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix | tp2.prefix)
568
576
case tp2 : TypeBounds if tp2 contains tp1 => tp2
569
- case _ => mergeConflict(tp1, tp2)
577
+ case _ => mergeConflict(tp1, tp2, that )
570
578
}
571
579
case tp1 : MethodOrPoly =>
572
580
tp2 match {
@@ -577,7 +585,7 @@ object Denotations {
577
585
mergeParamNames(tp1, tp2), tp1.paramInfos,
578
586
tp1.resultType | tp2.resultType.subst(tp2, tp1))
579
587
case _ =>
580
- mergeConflict(tp1, tp2)
588
+ mergeConflict(tp1, tp2, that )
581
589
}
582
590
case _ =>
583
591
tp1 | tp2
0 commit comments