This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Strange ambiguity error for imported private members

1 reply
hseeberger
Joined: 2008-12-27,
User offline. Last seen 1 year 25 weeks ago.
Hi,
Why does importing a private field lead to an ambiguity? In the below code Bar.baz should not be visible in FooBar and hence baz should unambiguously refer to Foo.baz:

object Foo {  val baz = "foo"}
object Bar {  private val baz = "foo"}
object FooBar {  import Foo._  import Bar._  val fooBar = baz}
test$ fsc test.scala test.scala:12: error: reference to baz is ambiguous;it is imported twice in the same scope byimport Bar._and import Foo._  val fooBar = baz
ThanksHeiko
--
Heiko Seeberger
Twitter: hseeberger
Blog: heikoseeberger.name
Company: Typesafe - Enterprise-Grade Scala from the Experts
Author of Durchstarten mit Scala, a German tutorial-style Scala book


Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Strange ambiguity error for imported private members
On Wed, Dec 14, 2011 at 2:39 PM, Heiko Seeberger <heiko.seeberger@googlemail.com> wrote:
Hi,
Why does importing a private field lead to an ambiguity? In the below code Bar.baz should not be visible in FooBar and hence baz should unambiguously refer to Foo.baz:

The only access modifier that prevents a name from being importable, and hence subject to ambiguity is private[this].
"4.7 The import expression determines a set of names of im- portable members of p which are made available without qualification. A member m of p is importable if it is not object-private.
It's definitely a bit of a gotcha when you expect people to wildcard import from your API (I made this mistake with Scalaz 6.0.2).
-jason

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland