From f4ad5357ffeb4b90777f73e4f1e32cbacbebd33c Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Tue, 14 Mar 2017 09:45:27 +0100 Subject: fix #2051: allow override T with => T or ()T --- compiler/src/dotty/tools/dotc/core/Types.scala | 7 ++++--- tests/pos/i2051.scala | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i2051.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 639f5d142..271dcda7c 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -727,8 +727,8 @@ object Types { /** Is this type a legal type for a member that overrides another * member of type `that`? This is the same as `<:<`, except that - * the types ()T and => T are identified, and T is seen as overriding - * either type. + * the types `()T`, `=> T` and `T` are seen as overriding + * each other. */ final def overrides(that: Type)(implicit ctx: Context) = { def result(tp: Type): Type = tp match { @@ -737,7 +737,8 @@ object Types { } (this frozen_<:< that) || { val rthat = result(that) - (rthat ne that) && (result(this) frozen_<:< rthat) + val rthis = result(this) + (rthat.ne(that) || rthis.ne(this)) && (rthis frozen_<:< rthat) } } diff --git a/tests/pos/i2051.scala b/tests/pos/i2051.scala new file mode 100644 index 000000000..d0e9fed0d --- /dev/null +++ b/tests/pos/i2051.scala @@ -0,0 +1,2 @@ +class A[T](val x:T) +class B[T](override val x:T) extends A[T](x) -- cgit v1.2.3 From c08ea413282b76865abbbda38addcbce35953f24 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Tue, 14 Mar 2017 11:23:05 +0100 Subject: add neg test for #2051 --- tests/neg/i2051.scala | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/neg/i2051.scala diff --git a/tests/neg/i2051.scala b/tests/neg/i2051.scala new file mode 100644 index 000000000..2295a05ab --- /dev/null +++ b/tests/neg/i2051.scala @@ -0,0 +1,2 @@ +abstract class C { val x: Int } +class D extends C { def x = 1 } // error: method x of type => Int needs to be a stable, immutable value -- cgit v1.2.3 From 864432373dc31b62529e5c221e3b8dca238aec18 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Tue, 14 Mar 2017 21:58:39 +0100 Subject: add more tests --- tests/pos/i2051.scala | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/pos/i2051.scala b/tests/pos/i2051.scala index d0e9fed0d..9e29eea22 100644 --- a/tests/pos/i2051.scala +++ b/tests/pos/i2051.scala @@ -1,2 +1,9 @@ class A[T](val x:T) class B[T](override val x:T) extends A[T](x) + +class C[T](val x:T, val y: Int, val z: Boolean) +class D[T](override val x:T, y: Int, z: Boolean) extends C[T](x, y, z) + +trait X(val x: Int, y: Int, z: Int) +trait Y(override val x: Int, y: Int, z: Int) extends X +class Z(override val x: Int, y: Int, z: Int) extends Y(x, y, z) with X(x, y, z) -- cgit v1.2.3