Skip to content

Non-visible symbol in wildcard import taking precedence over visible symbol in current package #12736

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

Closed
armanbilge opened this issue Feb 22, 2023 · 4 comments · Fixed by scala/scala#10325
Assignees
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR
Milestone

Comments

@armanbilge
Copy link

Reproduction steps

Scala version: 2.13.10

armanbilge/sandbox@0c6533c

Problem

sbt:sandbox> bar/compile
[info] compiling 1 Scala source to /workspace/sandbox/foo/target/scala-2.13/classes ...
[info] compiling 2 Scala sources to /workspace/sandbox/bar/target/scala-2.13/classes ...
[error] /workspace/sandbox/bar/src/main/scala/bar.scala:7:3: object Foo in package foo cannot be accessed as a member of package foo from object Bar in package baz
[error]   Foo
[error]   ^
[error] one error found
[error] (bar / Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed Feb 22, 2023, 7:15:12 AM
sbt:sandbox> 

Meanwhile, there is a visible Foo in the current package, which is the one we want.

@som-snytt
Copy link

➜  t12736 ls
bar.scala  baz.scala  foo.scala
➜  t12736 cat foo.scala

package foo

private object Foo
➜  t12736 cat bar.scala

package bar

private object Foo
➜  t12736 cat baz.scala

package bar
package baz

import foo._

object Bar {
  def test() = println(Foo)
}
➜  t12736 scalac -d /tmp *.scala
➜  t12736 scala -cp /tmp
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 19).
Type in expressions for evaluation. Or try :help.

scala> bar.baz.Bar.test()
bar.Foo$@619f2afc

scala>

Importable requires accessible.

Maybe try clean; compile.

@armanbilge
Copy link
Author

sbt:sandbox> clean; compile
[success] Total time: 0 s, completed Feb 22, 2023, 7:43:41 AM
[info] compiling 1 Scala source to /workspace/sandbox/foo/target/scala-2.13/classes ...
[info] compiling 2 Scala sources to /workspace/sandbox/bar/target/scala-2.13/classes ...
[error] /workspace/sandbox/bar/src/main/scala/bar.scala:7:3: object Foo in package foo cannot be accessed as a member of package foo from object Bar in package baz
[error]   Foo
[error]   ^
[error] one error found
[error] (bar / Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Feb 22, 2023, 7:43:41 AM
sbt:sandbox> 

@som-snytt
Copy link

I see the error after cloning the repo. Thanks!

@som-snytt
Copy link

som-snytt commented Feb 22, 2023

It's the separate compilation bug where it doesn't do "package private" correctly.

➜  t12736 scalac -d /tmp foo.scala
➜  t12736 scalac -d /tmp -cp /tmp b*.scala
baz.scala:8: error: object Foo in package foo cannot be accessed as a member of package foo from object Bar in package baz
  def test() = println(Foo)
                       ^
1 error

Not sure I knew it manifested this way, but it rings a bell.

The related issue was #8121

(Checking sym.exists around importedSelectedSymbol seems close. The fix for the related ticket was for checking the import, as opposed to performing the lookup.)

@som-snytt som-snytt self-assigned this Feb 22, 2023
@SethTisue SethTisue added this to the 2.13.11 milestone Feb 22, 2023
@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants