Skip to content

Commit dd85d57

Browse files
committed
Allow indirect inherited accessors
1 parent d1862de commit dd85d57

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,7 @@ object RefChecks {
516516
overrideError(i"needs to be declared with @targetName(${"\""}${other.targetName}${"\""}) so that external names match")
517517
else
518518
overrideError("cannot have a @targetName annotation since external names would be different")
519-
else if other.is(ParamAccessor)
520-
&& !(member.is(ParamAccessor) && ParamForwarding.inheritedAccessor(member) == other)
521-
then // (1.13)
519+
else if other.is(ParamAccessor) && !isInheritedAccessor(member, other) then // (1.13)
522520
if sourceVersion.isAtLeast(`future`) then
523521
overrideError(i"cannot override val parameter ${other.showLocated}")
524522
else
@@ -531,6 +529,13 @@ object RefChecks {
531529
overrideDeprecation("", member, other, "removed or renamed")
532530
end checkOverride
533531

532+
def isInheritedAccessor(mbr: Symbol, other: Symbol): Boolean =
533+
mbr.is(ParamAccessor)
534+
&& {
535+
val next = ParamForwarding.inheritedAccessor(mbr)
536+
next == other || isInheritedAccessor(next, other)
537+
}
538+
534539
OverridingPairsChecker(clazz, self).checkAll(checkOverride)
535540
printMixinOverrideErrors()
536541

tests/pos/i16092.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,16 @@ class B(override val x: Int) extends A(x)
33

44
class C(x: Int) extends A(x)
55
case class D(override val x: Int) extends C(x)
6+
7+
// The following is extracted from akka:
8+
trait LogEvent {
9+
def cause: Throwable
10+
}
11+
12+
/**
13+
* For ERROR Logging
14+
*/
15+
case class Error(override val cause: Throwable) extends LogEvent
16+
class Error2(override val cause: Throwable) extends Error(cause)
17+
class Error3(override val cause: Throwable) extends Error2(cause)
18+

0 commit comments

Comments
 (0)