- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Cannot use super when overriding values?!
Mon, 2011-08-22, 19:00
I have just stumbled upon this strange limitation.
abstract class Foo {
protected val bar1: Int = 1
protected def bar2: Int = 2
}
class Baz extends Foo {
override val bar1 = super.bar1 // Compiler: super may be not be use
on value bar1
override def bar2 = super.bar2
}
I get the message: "super may be not be use on value bar1". Besides
having strange grammar this limitation does not make sense to me.
Are there any reasons to prevent using super when overriding values or
is this a bug?
Mon, 2011-08-22, 19:37
#2
Re: Cannot use super when overriding values?!
(java)
public String x = "fsdfdsf";
how you are going to override a direct field access? if there was a "i
don't care about java interop", it would probably work.
Am 22.08.2011 20:21, schrieb Dhananjay Nene:
> On Mon, Aug 22, 2011 at 11:30 PM, Aleksey Nikiforov wrote:
>> I have just stumbled upon this strange limitation.
>>
>> abstract class Foo {
>> protected val bar1: Int = 1
>> protected def bar2: Int = 2
>> }
>>
>> class Baz extends Foo {
>> override val bar1 = super.bar1 // Compiler: super may be not be use
>> on value bar1
>> override def bar2 = super.bar2
>> }
>>
>> I get the message: "super may be not be use on value bar1". Besides
>> having strange grammar this limitation does not make sense to me.
>>
>> Are there any reasons to prevent using super when overriding values or
>> is this a bug?
>>
> Seems to be an intended behaviour as per
> https://issues.scala-lang.org/browse/SI-899
>
Mon, 2011-08-22, 19:47
#3
Re: Cannot use super when overriding values?!
To be clear, it is possible to override vals in Scala, so your
explanation is incorrect. What I was curious about is why it is not
possible to use super when overriding vals.
On Mon, Aug 22, 2011 at 1:28 PM, HamsterofDeath wrote:
> (java)
> public String x = "fsdfdsf";
>
> how you are going to override a direct field access? if there was a "i
> don't care about java interop", it would probably work.
>
Mon, 2011-08-22, 20:17
#4
Re: Cannot use super when overriding values?!
i've looked at it a bit deeper and now i don't see a reason why it
doesn't work, but i also don't see a reason why you would want to
override a field and not change it's value.
but i do remember stumbling on this a year ago and switching to defs
instead of vals for everything
Am 22.08.2011 20:34, schrieb Aleksey Nikiforov:
> To be clear, it is possible to override vals in Scala, so your
> explanation is incorrect. What I was curious about is why it is not
> possible to use super when overriding vals.
>
> On Mon, Aug 22, 2011 at 1:28 PM, HamsterofDeath wrote:
>> (java)
>> public String x = "fsdfdsf";
>>
>> how you are going to override a direct field access? if there was a "i
>> don't care about java interop", it would probably work.
>>
Mon, 2011-08-22, 23:17
#5
Re: Cannot use super when overriding values?!
I just wanted to change the visibility of a val from protected to
public. But as Iain has pointed out, many other use-cases are lost due
to this restriction.
On Mon, Aug 22, 2011 at 2:07 PM, HamsterofDeath wrote:
> i've looked at it a bit deeper and now i don't see a reason why it
> doesn't work, but i also don't see a reason why you would want to
> override a field and not change it's value.
>
> but i do remember stumbling on this a year ago and switching to defs
> instead of vals for everything
>
On Mon, Aug 22, 2011 at 11:30 PM, Aleksey Nikiforov wrote:
> I have just stumbled upon this strange limitation.
>
> abstract class Foo {
> protected val bar1: Int = 1
> protected def bar2: Int = 2
> }
>
> class Baz extends Foo {
> override val bar1 = super.bar1 // Compiler: super may be not be use
> on value bar1
> override def bar2 = super.bar2
> }
>
> I get the message: "super may be not be use on value bar1". Besides
> having strange grammar this limitation does not make sense to me.
>
> Are there any reasons to prevent using super when overriding values or
> is this a bug?
>
Seems to be an intended behaviour as per
https://issues.scala-lang.org/browse/SI-899