Skip to content

Check access rights of objects in import selectors #23081

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

Open
hamzaremmal opened this issue Apr 30, 2025 · 2 comments
Open

Check access rights of objects in import selectors #23081

hamzaremmal opened this issue Apr 30, 2025 · 2 comments
Assignees
Labels
area:import Issues tied to imports. itype:bug

Comments

@hamzaremmal
Copy link
Member

Compiler version

c4531d4

Minimized code

package bar:
  private[bar] object Bar

package foo:
  import bar.Bar   // no error
  val _ =  Bar     // error: not found (import is a no-op)
  val _ =  bar.Bar // error: access modifier

Output

-- [E006] Not Found Error: minim.scala:6:11 ------------------------------------
6 |  val _ =  Bar // error: not found (import is a no-op)
  |           ^^^
  |           Not found: Bar
  |
  | longer explanation available when compiling with `-explain`
-- [E173] Reference Error: minim.scala:7:15 ------------------------------------
7 |  val _ =  bar.Bar // error: access modifier
  |           ^^^^^^^
  |object Bar cannot be accessed as a member of bar.type from the top-level definitions in package foo.
  |  private[bar] object Bar can only be accessed from package bar.
2 errors found

Expectation

Have an error when importing an object that is not accessible from the current scope

@som-snytt
Copy link
Contributor

Might be tricky without forcing the enclosing foo. But since there is a typer error, you don't get an unused import (which could do an additional check).

I often mix up that importable implies accessible (per spec); for inheritance, matching requires non-private.

@som-snytt
Copy link
Contributor

Oh I forgot recent #22430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:import Issues tied to imports. itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants