Skip to content

Commit da945c4

Browse files
committed
Better handling of merge errors
Instead of picking one at random, throw a MergeError which might be caught later in mergeDenot. MergeDenot has enough info to pick a simulate Scala2 linarization if the prefix comes from Scala2, or it rethrows the exception so that it becomes a type error.
1 parent 746889b commit da945c4

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,17 @@ object Denotations {
308308
else if (!sym2.exists) sym1
309309
else if (preferSym(sym2, sym1)) sym2
310310
else sym1
311-
new JointRefDenotation(sym, info1 & info2, denot1.validFor & denot2.validFor)
311+
val jointInfo =
312+
try info1 & info2
313+
catch {
314+
case ex: MergeError =>
315+
if (pre.widen.classSymbol.is(Scala2x))
316+
info1 // follow Scala2 linearization -
317+
// compare with way merge is performed in SymDenotation#computeMembersNamed
318+
else
319+
throw new MergeError(s"${ex.getMessage} as members of type ${pre.show}")
320+
}
321+
new JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor)
312322
}
313323
}
314324
} else NoDenotation

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10571057
println(TypeComparer.explained { implicit ctx => tp1 <:< tp2})
10581058
assert(false, s"andConflict ${tp1.show} and ${tp2.show}")
10591059
*/
1060+
if (!ctx.isAfterTyper && !ctx.mode.is(Mode.Scala2Unpickling))
1061+
throw new MergeError(msg)
10601062
ctx.warning(msg, ctx.tree.pos)
10611063
winner
10621064
}

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,8 @@ object Types {
492492

493493
try go(this)
494494
catch {
495-
case ex: MergeError =>
496-
throw new MergeError(s"${ex.getMessage} as members of type ${pre.show}")
497495
case ex: Throwable =>
498-
ctx.println(i"findMember exception for $this member $name")
496+
core.println(i"findMember exception for $this member $name")
499497
throw ex // DEBUG
500498
}
501499
finally {

tests/neg/i827.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait A { trait Inner }
2+
trait B { self: A =>
3+
trait Inner extends self.Inner
4+
}
5+
6+
7+
class C extends C

0 commit comments

Comments
 (0)