A very strange thing indeed. I have the following project structure:
myproject/one/two
Inside package myproject I have a class:
abstract class A (two: Buffer[Int])
and then, inside package one I have:
object B extends A (Buffer[Int](1, 2, 3)) {
val с = two.map(_ + 1) // ERROR
}
However, the erros says:
object
mapis not a member of package
myproject/one/two
which is obviously erroneous because it should be perfectly clear that I don’t refer to the packages here, but to the local variable… And two also is not shown in context-assist after this. in B, but is shown in A (Scala-IDE). Is this an intended behavior and I am doing something wrong or is it a bug?
UPDATE:
(simultaneously suggested by Nicolas 😀 ) Been able to resolve the name collision by specifying two as val (making it public). I did not notice at first, but it was private and unavailable in the successor class. Nevertheless I am still wondering, why and how did Scala pick up a package instead of saying that the variable does not exist or is not accessible?
It’s not as clear as you might think. Without a modifier, two is private to abstract class A class
A. Thus your declaration ofais equivalent toabstract class A (private[this] A). It means that fieldtwocan’t be seen from objectB. A direct consequence is that the compiler look into the only defiition oftwovisible fromB: the packagetwo.