Skip to content

Fix #2051: allow override T with => T or ()T #2096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i2051.scala
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tests/pos/i2051.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class A[T](val x:T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to add several fields to the body of the class that are overriden in a subclass.

It would also be nice to include tests with trait vals and trait constructors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DarkDimius , I just added tests in the latest commit.

class B[T](override val x:T) extends A[T](x)