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 override var setters in sub-class of sub-class - "error overriding variable … cannot override a mutable variable" #12472

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

Comments

@Sciss
Copy link

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.

@SethTisue
Copy link
Member

SethTisue commented Oct 12, 2021

please report Scala 3 bugs at https://github.com/lampepfl/dotty/issues

@Sciss
Copy link
Author

Sciss commented Oct 12, 2021

sorry, I keep forgetting that the bug trackers are still separate

@SethTisue
Copy link
Member

SethTisue commented Oct 12, 2021

no worries 😀

scala/scala3#13738

@som-snytt
Copy link

som-snytt commented Oct 13, 2021

Duplicates #9840 (Edit: I read it wrong)

That would be a dotty feature-request.

@Sciss
Copy link
Author

Sciss commented Oct 27, 2021

I don't understand why it is a feature request. This works fine in Scala 2, and it is not comprehensible why if I define the Top trait interface, I have to go back to change the interface depending on some forms of later implementations. This doesn't make sense. I have just changed in one library

trait Scope {
   var logFreq: Boolean

   var logFreqMin: Double

   ... etc

to

trait Scope {
   def logFreq: Boolean
   def logFreq_=(value: Boolean): Unit

   def logFreqMin: Double
   def logFreqMin_(value: Double): Unit

   ... etc

purely defensively and in order to later implement that thing. I shouldn't need to change API definitions based on how the implementations (perhaps even in other libraries) are going. The duplicate issue you link to is very old imported from 2016 bug tracker and closed without resolution.

Voting to re-open this issue.

@Sciss Sciss changed the title Cannot overrwrite var setters in sub-class of sub-class - "error overriding variable … cannot override a mutable variable" Cannot override var setters in sub-class of sub-class - "error overriding variable … cannot override a mutable variable" Oct 27, 2021
@som-snytt
Copy link

IDK offhand, but I assumed it has to do with whether a field is allocated. Just analyzing aliased member fields is hard, but impossible with overridden accessors? Just guessing, and I'm not an expert.

@dwijnand
Copy link
Member

Voting to re-open this issue.

The issue is open (in the right tracker): scala/scala3#13738

@Sciss
Copy link
Author

Sciss commented Oct 27, 2021

The issue is open

🤦 I'll get this eventually

@som-snytt
Copy link

I was saying it's the wrong tracker, it should be a feature request. :)

@som-snytt
Copy link

Sorry, somehow I missed that the var is abstract here. I fixed the dotty issue under a different ticket after 3.1.0.

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

No branches or pull requests

4 participants