Skip to content
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

Cannot overrwrite var setters in sub-class of sub-class - "error overriding variable … cannot override a mutable variable" #13738

Closed
Sciss opened this issue Oct 12, 2021 · 2 comments

Comments

@Sciss
Copy link
Contributor

Sciss commented Oct 12, 2021

reproduction steps

using Scala 3.0.2,

trait Foo

trait Top:
  var foo: Foo

trait Middle extends Top:
  def foo: Foo = ???
  def foo_=(value: Foo): Unit = ???

class Bottom extends Middle:
  // error overriding variable foo in trait Top of type Foo;
  // method foo_= of type (value: Foo): Unit cannot override a mutable variable
  override def foo_=(value: Foo): Unit =
    super.foo_=(value)
    println("Helo")

If I rewrite Top as

trait Top:
  def foo: Foo
  def foo_=(value: Foo): Unit

"it works"

problem

I think it should always be possible to override getters and setters for a var.

@odersky
Copy link
Contributor

odersky commented Dec 5, 2021

I could not reproduce. It works for me when I compile with nightly.

@som-snytt
Copy link
Contributor

Duplicates #13019 which I contributed because of the linked scala 2 ticket (which it also duplicates).

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

4 participants