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