summaryrefslogtreecommitdiff
path: root/test/files/neg/t3871b.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-10-09 16:56:12 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-10-23 14:38:47 +0200
commitb39a509213f7b43185cca3e633c9211abdc0f126 (patch)
treeaa4c4afd813a734c4a5abe78ee587dd11125d23b /test/files/neg/t3871b.scala
parent4d9631449fdf960c1bc56ac8ad43e3334c54f180 (diff)
downloadscala-b39a509213f7b43185cca3e633c9211abdc0f126.tar.gz
scala-b39a509213f7b43185cca3e633c9211abdc0f126.tar.bz2
scala-b39a509213f7b43185cca3e633c9211abdc0f126.zip
SI-3871 Testing protected access against the spec
I've marked a few minor cases in the test with !!! where I believe the behaviour goes beyond the spec.
Diffstat (limited to 'test/files/neg/t3871b.scala')
-rw-r--r--test/files/neg/t3871b.scala127
1 files changed, 127 insertions, 0 deletions
diff --git a/test/files/neg/t3871b.scala b/test/files/neg/t3871b.scala
new file mode 100644
index 0000000000..b490b7789a
--- /dev/null
+++ b/test/files/neg/t3871b.scala
@@ -0,0 +1,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
+ }
+}