- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Scala-Reference: error about name bindings?
Hello,
I'm trying to compile the code showned in chapter 2 of Scala Reference from May 11, 2011, pages 16 and 17, about import and bindings.
Unfortunatly, it seems to not be consistent with what scalac 2.8.1 and 2.9.0-1 implements, and so I believe I made some kind of mistake. Please, could somebody explains what I'm doing wrong ?
Here is the actual code I try to compile (copy/paste from the spec does not work really well, so perhaps it's just an error here):
=========
package P {
object X { val x = 1; val y = 2 }
}
package Q {
object X { val x = true; val y = "" }
}
package P {
import Console._
object A {
println("L4: "+X)
object B {
import Q._
println("L7: "+X)
import X._
println("L8: "+x)
object C {
val x = 3
println("L12: "+x)
{ import Q.X._
println("L14: "+x)
import X.y
println("L16: "+y)
{ val x = "abc"
import P.X._
println("L19: "+y)
println("L20: "+x)
}}}}}}
=========
scalac 2.8.1 errors:
============
% ~/java/scala-2.8.1.final/bin/scalac TestNameSpace.scala
TestNameSpace.scala:16: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
println("L7: "+X)
^
TestNameSpace.scala:17: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
import X._
^
TestNameSpace.scala:22: error: scala.Console.println("L12: ".+(C.this.x)) of type Unit does not take parameters
{ import Q.X._
^
three errors found
scala 2.9.0-1 errors:
============
% ~/java/scala-2.9.0.1/bin/scalac TestNameSpace.scala
TestNameSpace.scala:16: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
println("L7: "+X)
^
TestNameSpace.scala:17: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
import X._
^
TestNameSpace.scala:22: error: Unit does not take parameters
{ import Q.X._
^
three errors found
========
Thanks,
I'm trying to compile the code showned in chapter 2 of Scala Reference from May 11, 2011, pages 16 and 17, about import and bindings.
Unfortunatly, it seems to not be consistent with what scalac 2.8.1 and 2.9.0-1 implements, and so I believe I made some kind of mistake. Please, could somebody explains what I'm doing wrong ?
Here is the actual code I try to compile (copy/paste from the spec does not work really well, so perhaps it's just an error here):
=========
package P {
object X { val x = 1; val y = 2 }
}
package Q {
object X { val x = true; val y = "" }
}
package P {
import Console._
object A {
println("L4: "+X)
object B {
import Q._
println("L7: "+X)
import X._
println("L8: "+x)
object C {
val x = 3
println("L12: "+x)
{ import Q.X._
println("L14: "+x)
import X.y
println("L16: "+y)
{ val x = "abc"
import P.X._
println("L19: "+y)
println("L20: "+x)
}}}}}}
=========
scalac 2.8.1 errors:
============
% ~/java/scala-2.8.1.final/bin/scalac TestNameSpace.scala
TestNameSpace.scala:16: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
println("L7: "+X)
^
TestNameSpace.scala:17: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
import X._
^
TestNameSpace.scala:22: error: scala.Console.println("L12: ".+(C.this.x)) of type Unit does not take parameters
{ import Q.X._
^
three errors found
scala 2.9.0-1 errors:
============
% ~/java/scala-2.9.0.1/bin/scalac TestNameSpace.scala
TestNameSpace.scala:16: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
println("L7: "+X)
^
TestNameSpace.scala:17: error: reference to X is ambiguous;
it is both defined in package P and imported subsequently by
import Q._
import X._
^
TestNameSpace.scala:22: error: Unit does not take parameters
{ import Q.X._
^
three errors found
========
Thanks,
-- Francois ARMAND http://fanf42.blogspot.com http://www.normation.com










Re: Scala-Reference: error about name bindings?
Sorry, that mail wasn't meant for that list... Excuse me for the noise (and my bad auto-completion skill)