-
Notifications
You must be signed in to change notification settings - Fork 21
ambiguous reference with imports #2133
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2133?orig=1 |
@paulp said: It's even more problematic than illustrated above. Here is how I ran into it: trait Foo {
object bar {
private[this] def fn() = 5
}
}
trait Foo2 {
object bip {
def fn() = 10
}
}
class Bob extends AnyRef with Foo with Foo2 {
import bip._
import bar._
def go() = fn()
}
// a.scala:17: error: reference to fn is ambiguous;
// it is imported twice in the same scope by
// import bar._
// and import bip._
// def go() = fn()
// ^ It fails no matter what visibility restrictions one places on it - private, private[foo], private[this]. |
@paulp said: |
@odersky said: |
@Blaisorblade said: scala> object Foo {
| private def println(x: Any) {}
| }
defined module Foo
scala> import Foo._
import Foo._
scala> println(1)
<console>:12: error: method println in object Foo cannot be accessed in object Foo
println(1)
^ Getting compile errors from private members violates the principle of encapsulation: adding a private member to a class cannot be allowed to affect code where that member is not accessible. |
@paulp said: |
@Blaisorblade said: |
@odersky said: |
Ryan Hendrickson (ryan.hendrickson_bwater) said: |
@gkossakowski said: |
@lrytz said: |
@lrytz said: object Foo {
def s = "foo"
}
object Bar {
private def s = "bar"
}
object Test {
import Foo._
import Bar._
println(s)
} |
Implementation was massaged to fix 2133, 3160, 3836 and related tickets around import ergonomics, but the spec lagged. This specifies importing multiple type aliases and that importable requires accessible. Fixes scala/bug#2133
The following code should print out "1" but instead
produces the error
both with Scala 2.7.5 and trunk. The
import f._
statement should not see the private memberx
in classFoo
.The text was updated successfully, but these errors were encountered: