Skip to content
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

Objects leak protected inner classes #22560

Open
amordahl opened this issue Feb 9, 2025 · 1 comment · May be fixed by #22563
Open

Objects leak protected inner classes #22560

amordahl opened this issue Feb 9, 2025 · 1 comment · May be fixed by #22563

Comments

@amordahl
Copy link

amordahl commented Feb 9, 2025

Compiler version

3.6.3

Minimized code

class A:
  protected class B

// This fails to compile, as expected
// val x = A().B()

object C:
  protected val p = "protected"
  protected def getString() = "Hello!"
  protected class D

// This fails to compile
// val y = C.p

// And this also fails to compile
// val z = C.getString()

// However, this compiles just fine.
val alpha = C.D()

Output

The code compiles, even though a protected inner class is being accessed outside of the declaring object.

Expectation

I know that there isn't any point in declaring members of objects protected, since an object can't be extended. However, the way that protected inner classes are handled (which, as far as I can tell, is to ignore the protected keyword) is inconsistent with the way that protected vars/vals/defs are treated inside objects.

@amordahl amordahl added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 9, 2025
@som-snytt
Copy link
Contributor

som-snytt commented Feb 9, 2025

That is an artifact of the constructor proxy.

21 |val beta = new C.D()
   |               ^^^
   |class D cannot be accessed as a member of C.type from the top-level definitions in package <empty>.
   |  protected class D can only be accessed from object C.
1 error found

Similar to #18545

@som-snytt som-snytt linked a pull request Feb 9, 2025 that will close this issue
@som-snytt som-snytt self-assigned this Feb 9, 2025
@som-snytt som-snytt added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants