- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Should scalac give warnings or errors for identifiers in scope hidden by a supertype
Sat, 2008-12-27, 16:07
Hi,
abstract class Foo { val bar = 5 }
object Main { def main(args: Array[String]) = {
val bar = 10
new Foo { def spam = println(bar) }.spam
} }
In the above, it is the bar from Foo (5) that gets printed, because the supertype's members shadow the members from the enclosing scope.
My suggestion is that scalac begin to give warnings (or errors) for the *use* of identifiers for which the supertype's member takes precedence over the member from the enclosing scope.
I didn't report it as a bug/RFE, because it seems subjective.
Please, pick faults.
(It caused me some confusion when using specs. The appropriate specs bug report: http://code.google.com/p/specs/issues/detail?id=47 )
Cheers,
Ricky.
abstract class Foo { val bar = 5 }
object Main { def main(args: Array[String]) = {
val bar = 10
new Foo { def spam = println(bar) }.spam
} }
In the above, it is the bar from Foo (5) that gets printed, because the supertype's members shadow the members from the enclosing scope.
My suggestion is that scalac begin to give warnings (or errors) for the *use* of identifiers for which the supertype's member takes precedence over the member from the enclosing scope.
I didn't report it as a bug/RFE, because it seems subjective.
Please, pick faults.
(It caused me some confusion when using specs. The appropriate specs bug report: http://code.google.com/p/specs/issues/detail?id=47 )
Cheers,
Ricky.
Sat, 2010-12-04, 10:46
#2
Это мы торчим н
Это мы торчим на этой жуткой планете месяцы и месяцы на неразведанной территории совсем одни, и неизвестно, какие опасности нас подстерегают Должны же мы хоть что-то получить взамен









Ricky Clarkson wrote:
> Hi,
>
> abstract class Foo { val bar = 5 }
>
> object Main { def main(args: Array[String]) = {
> val bar = 10
> new Foo { def spam = println(bar) }.spam
> } }
>
> In the above, it is the bar from Foo (5) that gets printed, because the
> supertype's members shadow the members from the enclosing scope.
>
> My suggestion is that scalac begin to give warnings (or errors) for the
> *use* of identifiers for which the supertype's member takes precedence
> over the member from the enclosing scope.
>
> I didn't report it as a bug/RFE, because it seems subjective.
IMO, the problem is not primarily to figure out which method is called,
but rather that there is possibility for method "high jacking". The same
problem can be found in:
import A._
{
import B._
foo
}
Now if initially there is no B.foo, A.foo will be used, but if later foo
is added to B it will be used instead, thus it's "high jacked". I think
this might be cause enough to issue a warning when this type of "high
jacking" can occur. Note that an error will be issued for this code:
import A._
import B._
foo
/Jesper Nordenberg