Skip to content

Commit 5d692bf

Browse files
committed
Fix #6089: Handle super-accessors involving ()T to => T overrides
1 parent c616b06 commit 5d692bf

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

compiler/src/dotty/tools/dotc/transform/MixinOps.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,17 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
7272
final val PrivateOrAccessorOrDeferred: FlagSet = Private | Accessor | Deferred
7373

7474
def forwarderRhsFn(target: Symbol): List[Type] => List[List[Tree]] => Tree =
75-
targs => vrefss =>
76-
superRef(target).appliedToTypes(targs).appliedToArgss(vrefss)
75+
targs => vrefss => {
76+
val tapp = superRef(target).appliedToTypes(targs)
77+
vrefss match {
78+
case Nil | List(Nil) =>
79+
// Overriding is somewhat loose about `()T` vs `=> T`, so just pick
80+
// whichever makes sense for `target`
81+
tapp.ensureApplied
82+
case _ =>
83+
tapp.appliedToArgss(vrefss)
84+
}
85+
}
7786

7887
private def competingMethodsIterator(meth: Symbol): Iterator[Symbol] = {
7988
cls.baseClasses.iterator

compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object ResolveSuper {
9292
// of the superaccessor's type, see i5433.scala for an example where this matters
9393
val otherTp = other.asSeenFrom(base.typeRef).info
9494
val accTp = acc.asSeenFrom(base.typeRef).info
95-
if (!(otherTp <:< accTp))
95+
if (!(otherTp.overrides(accTp, matchLoosely = true)))
9696
ctx.error(IllegalSuperAccessor(base, memberName, acc, accTp, other.symbol, otherTp), base.sourcePos)
9797
}
9898

tests/pos/i6089.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait X { override def toString = super.toString + " X" }
2+
trait Y { override def toString = super.toString + " Y" }
3+
class Z extends X with Y

0 commit comments

Comments
 (0)