diff options
author | Dmitry Petrashko <dark@d-d.me> | 2017-03-15 13:04:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-15 13:04:43 +0100 |
commit | 72d5aaadbac78ccdf4aab9f2b2f426a1e34c9974 (patch) | |
tree | a63a056c25100d3aa0a6a7bf7db049a70016b20e | |
parent | 141fb4b8c63e5b9cbbb1b92f55412e676a38cbf0 (diff) | |
parent | 864432373dc31b62529e5c221e3b8dca238aec18 (diff) | |
download | dotty-72d5aaadbac78ccdf4aab9f2b2f426a1e34c9974.tar.gz dotty-72d5aaadbac78ccdf4aab9f2b2f426a1e34c9974.tar.bz2 dotty-72d5aaadbac78ccdf4aab9f2b2f426a1e34c9974.zip |
Merge pull request #2096 from dotty-staging/fix-i2051
Fix #2051: allow override T with => T or ()T
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Types.scala | 7 | ||||
-rw-r--r-- | tests/neg/i2051.scala | 2 | ||||
-rw-r--r-- | tests/pos/i2051.scala | 9 |
3 files changed, 15 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8e852a9a9..abc496ec0 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/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 diff --git a/tests/pos/i2051.scala b/tests/pos/i2051.scala new file mode 100644 index 000000000..9e29eea22 --- /dev/null +++ b/tests/pos/i2051.scala @@ -0,0 +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) |