Skip to content

Commit cfc9058

Browse files
committed
Relax restriction about type overrides
Allow several type aliases if they are the same.
1 parent 51bff8d commit cfc9058

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ object Types {
991991
case tp: TypeRef =>
992992
if (tp.symbol.isClass) tp
993993
else tp.info match {
994-
case TypeAlias(tp) => tp.dealias1(keepAnnots): @tailrec
994+
case TypeAlias(alias) => alias.dealias1(keepAnnots): @tailrec
995995
case _ => tp
996996
}
997997
case app @ AppliedType(tycon, args) =>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,10 @@ object RefChecks {
343343
if (autoOverride(member) ||
344344
other.owner.is(JavaTrait) && ctx.testScala2Mode("`override' modifier required when a Java 8 default method is re-implemented", member.pos))
345345
member.setFlag(Override)
346-
else if (member.owner != clazz && other.owner != clazz && !(other.owner derivesFrom member.owner))
346+
else if (member.isType && self.memberInfo(member) =:= self.memberInfo(other))
347+
() // OK, don't complain about type aliases which are equal
348+
else if (member.owner != clazz && other.owner != clazz &&
349+
!(other.owner derivesFrom member.owner))
347350
emitOverrideError(
348351
clazz + " inherits conflicting members:\n "
349352
+ infoStringWithLocation(other) + " and\n " + infoStringWithLocation(member)

tests/pos/this-types.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait A {
2+
type A_This <: A
3+
}
4+
trait B extends A {
5+
type A_This = B_This
6+
type B_This <: B
7+
}
8+
trait C extends A {
9+
type A_This = C_This
10+
type C_This <: C
11+
}
12+
trait D extends B with C {
13+
type B_This = D_This
14+
type C_This = D_This
15+
type D_This <: D
16+
}

0 commit comments

Comments
 (0)