Skip to content

When a val overrides an abstract var #36

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

Closed
scabug opened this issue Aug 31, 2007 · 3 comments
Closed

When a val overrides an abstract var #36

scabug opened this issue Aug 31, 2007 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 31, 2007

The error message produced when you override an abstract var with a val is unclear,

For example:

abstract class A {
        var x : Int
}

class B extends A {
        val x = 2
}

produces the error:

error.scala:5: error: class B needs to be abstract, since variable x in class A of type Int is not defined
(Note that variables need to be initialized to be defined)
class B extends A {
^

It wuold be more obvious if this produced the same error as overriding a concrete var with a val, e.g.

abstract class A {
        var x = 1
}

class B extends A {
        override val x = 2
}

with the error message:

error.scala:6: error: error overriding variable x in class A of type Int;
 value x cannot override a mutable variable
        override val x = 2
                     ^
@scabug
Copy link
Author

scabug commented Aug 31, 2007

Imported From: https://issues.scala-lang.org/browse/SI-36?orig=1
Reporter: Commit Message Bot (anonymous)

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone postponed deleted

@scabug
Copy link
Author

scabug commented Jul 2, 2010

@paulp said:
(In r22481) When compilation fails because of an unimplemented abstract var,
give a more precise error message about what happened. Also avoid
issuing the same error twice because neither getter nor setter is
implemented. Closes #36, review by rytz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants