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
traits should be able to call super on fields #1938
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1938?orig=1 |
Antony Stubbs (astubbs) said: |
Tony Sloane (asloane) said: It would be extremely useful when extending combinator parsers where a base language trait defines some parsers as vals (or lazy vals), then an extension language trait wants to override the parser to add some new constructs, but default back to the base language parser. There are some work-arounds where the vals are wrapped by defs, but the boilerplate gets in teh way of the cleanest expression of this kind of composition. |
@paulbutcher said: |
Erik Bruchez (ebruchez) said: |
Ivan Fryda (ivanfoofoo) said (edited on Nov 29, 2011 10:48:03 PM UTC): class Topping(var name:String)}} That class definition should create the implicit getter and setter for its name attribute. Then, I create a trait this way: trait LoggingNameTrait extends Topping {
override def name_=(aName:String) {
print(aName)
super.name_=(aName) // this line doesn't compile
}
} The Scala compiler doesn't let me trait-overwrite the setter for the name attribute. Is this supposed to work this way (some kind of a language limitation)? |
Tomer Gabel (holograph) said: |
@retronym said: ~/code/scala ./build/quick/bin/scala -Yoverride-vars
Welcome to Scala version 2.10.0-20120701-125412-ad51d82953 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class Base { val a = 1; def b = 0 }; class Derived extends Base { override val a = super.a + 1 }
defined class Base
defined class Derived
scala> new Derived().a
res0: Int = 2
scala> trait Base { val a = 1; def b = 0 }; class Derived extends Base { override val a = super.a + 1 }
defined trait Base
defined class Derived
scala> new Derived().a
res1: Int = 1 |
@paulp said: |
@retronym said: |
B. Tommy Jensen (tommy-at-grindvoll.com) said: |
is this still an issue in 2.12? |
I'm pretty sure it is. |
As expressed by martin in #1093:
I'm closing that one and opening this one so it's not buried in a comment.
The text was updated successfully, but these errors were encountered: