Skip to content

Commit 72d5aaa

Browse files
authored
Merge pull request #2096 from dotty-staging/fix-i2051
Fix #2051: allow override T with => T or ()T
2 parents 141fb4b + 8644323 commit 72d5aaa

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ object Types {
727727

728728
/** Is this type a legal type for a member that overrides another
729729
* member of type `that`? This is the same as `<:<`, except that
730-
* the types ()T and => T are identified, and T is seen as overriding
731-
* either type.
730+
* the types `()T`, `=> T` and `T` are seen as overriding
731+
* each other.
732732
*/
733733
final def overrides(that: Type)(implicit ctx: Context) = {
734734
def result(tp: Type): Type = tp match {
@@ -737,7 +737,8 @@ object Types {
737737
}
738738
(this frozen_<:< that) || {
739739
val rthat = result(that)
740-
(rthat ne that) && (result(this) frozen_<:< rthat)
740+
val rthis = result(this)
741+
(rthat.ne(that) || rthis.ne(this)) && (rthis frozen_<:< rthat)
741742
}
742743
}
743744

tests/neg/i2051.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
abstract class C { val x: Int }
2+
class D extends C { def x = 1 } // error: method x of type => Int needs to be a stable, immutable value

tests/pos/i2051.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A[T](val x:T)
2+
class B[T](override val x:T) extends A[T](x)
3+
4+
class C[T](val x:T, val y: Int, val z: Boolean)
5+
class D[T](override val x:T, y: Int, z: Boolean) extends C[T](x, y, z)
6+
7+
trait X(val x: Int, y: Int, z: Int)
8+
trait Y(override val x: Int, y: Int, z: Int) extends X
9+
class Z(override val x: Int, y: Int, z: Int) extends Y(x, y, z) with X(x, y, z)

0 commit comments

Comments
 (0)