Skip to content

Can we please reach some kind of decision on access #6794

Closed as not planned
Closed as not planned
@scabug

Description

@scabug

I've tried for years to obtain some clarity here. It is a large tax on users and compiler developers alike that even if people knew and understood what is supposed to work and how it's supposed to work with respect to the 16 permutations of qualified/object private/protected type/value visibility/access - which they don't, myself included - that knowledge would be of limited use because there are so many bugs.

The bugs persist in large part because I lack sufficient information to fix them. It would be wonderful if we could make some forward progress on this somehow. This is a small sample of the set of behaviors which are hard to explain or defend (although I admit to the possibility that all of this is "as specified" since as I said, I am incapable of deriving the intended behavior from the specification.)

trait FB[T <: FB[T]] { }

package foo {
  class Bippy {
    private[Bippy] class FB1 extends FB[FB1]
    private[foo] class FB2 extends FB[FB2]
    protected[this] class FB3 extends FB[FB3]
    protected class FB4 extends FB[FB4]

    def f1 = new FB1
    def f2 = new FB2
    def f3 = new FB3
    def f4 = new FB4
  }
}

/****

scala> val x = new foo.Bippy
x: foo.Bippy = foo.Bippy@62b6772

scala> x.f1
res0: x.FB1 = foo.Bippy$FB1@4bfd366a

scala> x.f2
res1: x.FB2 = foo.Bippy$FB2@16fc39cd

scala> x.f3
res2: x.FB3 = foo.Bippy$FB3@d72f8f7

scala> x.f4
res3: x.FB4 = foo.Bippy$FB4@104a73cb

scala> var y: x.FB1 = _
<console>:8: error: class FB1 in class Bippy cannot be accessed in foo.Bippy
       var y: x.FB1 = _
                ^

scala> var y: x.FB2 = _
<console>:8: error: class FB2 in class Bippy cannot be accessed in foo.Bippy
       var y: x.FB2 = _
                ^

scala> var y: x.FB3 = _
<console>:8: error: type FB3 is not a member of foo.Bippy
       var y: x.FB3 = _
                ^

scala> var y: x.FB4 = _
<console>:8: error: class FB4 in class Bippy cannot be accessed in foo.Bippy
 Access to protected class FB4 not permitted because
 enclosing object $iw is not a subclass of
 class Bippy in package foo where target is defined
       var y: x.FB4 = _
                ^

After all that, god forbid we let 'private class FB5' escape...

scala> private class FB5 ; def f5 = new FB5
<console>:7: error: private class FB5 escapes its defining scope as part of type FB5
       private class FB5 ; def f5 = new FB5
                               ^

***/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions