test/tools/javac/QualifiedAccess/QualifiedAccess_1.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
equal deleted inserted replaced
-1:000000000000 0:959103a6100f
1 /**
2 * @test /nodynamiccopyright/
3 * @bug 4094658 4277296 4785453
4 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
5 * the type to which a component member belongs be accessible in qualified
6 * names.
7 *
8 * @compile pack1/P1.java
9 * @compile pack1/P2.java
10 * @compile/fail/ref=QualifiedAccess_1.out -XDrawDiagnostics QualifiedAccess_1.java
11 */
12
13 import pack1.P1;
14
15 public class QualifiedAccess_1 {
16
17 // Inaccessible types in member declarations.
18 // These exercise 'Env.resolve'.
19 // Errors are localized poorly.
20 //
21 // Fields 'P3' and 'P5' are inaccessible.
22
23 P1 foo;
24 P1.P3 bar; // ERROR
25 P1.P3.P4 baz; // ERROR
26 P1.P3.P4.P5 quux; // ERROR
27
28 P1 m11() {return null;}
29 P1.P3 m12() {return null;} // ERROR
30 P1.P3.P4 m13() {return null;} // ERROR
31 P1.P3.P4.P5 m14() {return null;} // ERROR
32
33 void m21(P1 x) {}
34 void m22(P1.P3 x) {} // ERROR
35 void m23(P1.P3.P4 x) {} // ERROR
36 void m24(P1.P3.P4.P5 x) {} // ERROR
37
38 void test1() {
39
40 // Inaccessible types in local variable declarations.
41 // These exercise 'FieldExpression.checkCommon'.
42 //
43 // Fields 'P3' and 'P5' are inaccessible.
44
45 P1 foo = null;
46 P1.P3 bar = null; // ERROR
47 P1.P3.P4 baz = null; // ERROR
48 P1.P3.P4.P5 quux = null; // ERROR
49 }
50
51 void test2() {
52
53 // Inaccessible types in casts.
54 // These exercise 'FieldExpression.checkCommon'.
55 //
56 // Fields 'P3' and 'P5' are inaccessible.
57
58 Object foo = (P1)null;
59 Object bar = (P1.P3)null; // ERROR
60 Object baz = (P1.P3.P4)null; // ERROR
61 Object quux = (P1.P3.P4.P5)null; // ERROR
62 }
63
64 void test3() {
65
66 // Inaccessible types in 'instanceof' expressions.
67 // These exercise 'FieldExpression.checkCommon'.
68 //
69 // Fields 'P3' and 'P5' are inaccessible.
70
71 boolean foo = null instanceof P1;
72 boolean bar = null instanceof P1.P3; // ERROR
73 boolean baz = null instanceof P1.P3.P4; // ERROR
74 boolean quux = null instanceof P1.P3.P4.P5; // ERROR
75 }
76
77 }

mercurial