1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/**
The protected modifier applies to class member definitions. Protected members of a class can be accessed from within
0a. the companion module of any of those classes
A protected identifier x may be used as a member name in a selection r.x only
if one of the following applies:
1a. The access is within the template defining the member, or,
if a qualification C is given,
1b. inside the package C, or
1c. the class C , or its companion module, or
2. r is one of the reserved words this and super, or
3. r’s type conforms to a type-instance of the class which contains the access.
4. A different form of qualification is protected[this]. A member M marked with this
modifier is called object-protected; it can be accessed only from within the object
in which it is defined. That is, a selection p.M is only legal if the prefix is this
or O.this, for some class O enclosing the reference. In addition, the restrictions
for unqualified protected apply.
*/
object E {
val e = new E
import e._
def n(a: A, b: B, c: C) = {
b.protE // 1c
c.protE // 1c
a.protE // 1c
A.protOE // 1c
}
}
class E {
object A {
protected def protO = 2
protected[E] def protOE = 3
protected[this] def protOT = 3
}
class A {
protected def prot = 2
protected[E] def protE = 3
protected[this] def protT = 4
// 1a
prot; protE; protT
def foo = {prot; protE; protT}
new { prot; protE }
def this(a: Any) = {this(); prot; protE; protT}
object B extends A {
A.this.prot
A.this.protE
A.this.protT
}
import A._
// 0a
protO
// 3
protOE
protOT // not allowed
}
class B extends A {
// 1b
this.prot; this.protE;
super.prot; super.protE;
// 4
this.protT
// 4 !!! "or the super keyword"
super.protT
def n(a: A, b: B, c: C) = {
b.prot // 3
c.prot // 3
a.prot // not allowed, prefix type `A` does not conform to `B`
b.protT // not allowed
c.protT // not allowed
a.protT // not allowed
}
}
object B {
def n(a: A, b: B, c: C) = {
b.prot // 3 !!!
c.prot // 3 !!!
// Wording of 3 seems insufficient, missing:
// "... (if the access is from a class), or
// the type instance of companion class (if the access is from a module)"
a.prot // not allowed
b.protT // not allowed
c.protT // not allowed
a.protT // not allowed
}
}
class C extends B
class Z {
def n(a: A, b: B, c: C) = {
b.prot // not allowed
c.prot // not allowed
a.prot // not allowed
b.protE // 2
a.protE // 2
c.protE // 2
b.protT // not allowed
c.protT // not allowed
a.protT // not allowed
}
}
}
class Other {
val e = new E
import e._
def n(a: A, b: B, c: C) = {
b.prot // not allowed
c.prot // not allowed
a.prot // not allowed
b.protE // not allowed
a.protE // not allowed
c.protE // not allowed
}
}
|