### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.670 diff -u -r1.670 GenericTypeTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 2 Nov 2007 14:02:21 -0000 1.670 +++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 8 Nov 2007 14:46:33 -0000 @@ -40592,5 +40592,219 @@ " ^^^^^^\n" + "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 +public void test1212() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public interface Loader {\n" + + " public T load(final K key);\n" + + " }\n" + + " Loader loader;\n" + + " public T get(final K key) {\n" + + " T data = this.loader.load(key);\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation +public void test1213() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " return (z? x1: x2);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 +public void test1214() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " private class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\A.java (at line 18)\n" + + " this.box.set(new P());\n" + + " ^^^^^^^\n" + + "Access to enclosing constructor A.P() is emulated by a synthetic accessor method. Increasing its visibility will improve your performance\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation +public void test1215() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " protected class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation +public void test1216() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n"); } } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java,v retrieving revision 1.98 diff -u -r1.98 SingleNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 13 Sep 2007 08:54:50 -0000 1.98 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 8 Nov 2007 14:46:37 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.impl.*; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -228,6 +229,16 @@ ? compileTimeType // unboxing: checkcast before conversion : runtimeTimeType; this.genericCast = originalType.genericCast(scope.boxing(targetType)); + if (this.genericCast instanceof ReferenceBinding) { + ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast; + if (!referenceCast.canBeSeenBy(scope)) { + scope.problemReporter().invalidType(this, + new ProblemReferenceBinding( + CharOperation.splitOn('.', referenceCast.shortReadableName()), + referenceCast, + ProblemReasons.NotVisible)); + } + } } } super.computeConversion(scope, runtimeTimeType, compileTimeType); Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java,v retrieving revision 1.112 diff -u -r1.112 FieldReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java 25 Oct 2007 14:02:13 -0000 1.112 +++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldReference.java 8 Nov 2007 14:46:35 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.impl.*; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -127,6 +128,16 @@ ? compileTimeType // unboxing: checkcast before conversion : runtimeTimeType; this.genericCast = originalBinding.type.genericCast(targetType); + if (this.genericCast instanceof ReferenceBinding) { + ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast; + if (!referenceCast.canBeSeenBy(scope)) { + scope.problemReporter().invalidType(this, + new ProblemReferenceBinding( + CharOperation.splitOn('.', referenceCast.shortReadableName()), + referenceCast, + ProblemReasons.NotVisible)); + } + } } } super.computeConversion(scope, runtimeTimeType, compileTimeType); Index: compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java,v retrieving revision 1.125 diff -u -r1.125 MessageSend.java --- compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 2 Nov 2007 11:24:15 -0000 1.125 +++ compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 8 Nov 2007 14:46:36 -0000 @@ -27,6 +27,7 @@ import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; +import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.Scope; @@ -98,7 +99,7 @@ TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) ? compileTimeType // unboxing: checkcast before conversion : runtimeTimeType; - this.valueCast = originalType.genericCast(targetType); + this.valueCast = originalType.genericCast(targetType); } else if (this.actualReceiverType.isArrayType() && runtimeTimeType.id != TypeIds.T_JavaLangObject && this.binding.parameters == Binding.NO_PARAMETERS @@ -107,6 +108,16 @@ // from 1.5 compliant mode on, array#clone() resolves to array type, but codegen to #clone()Object - thus require extra inserted cast this.valueCast = runtimeTimeType; } + if (this.valueCast instanceof ReferenceBinding) { + ReferenceBinding referenceCast = (ReferenceBinding) this.valueCast; + if (!referenceCast.canBeSeenBy(scope)) { + scope.problemReporter().invalidType(this, + new ProblemReferenceBinding( + CharOperation.splitOn('.', referenceCast.shortReadableName()), + referenceCast, + ProblemReasons.NotVisible)); + } + } } super.computeConversion(scope, runtimeTimeType, compileTimeType); } Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java,v retrieving revision 1.119 diff -u -r1.119 QualifiedNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 24 Sep 2007 22:49:54 -0000 1.119 +++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 8 Nov 2007 14:46:36 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; @@ -25,6 +26,7 @@ import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding; +import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.Scope; @@ -351,7 +353,18 @@ TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType()) ? compileTimeType // unboxing: checkcast before conversion : runtimeTimeType; - setGenericCast(length, originalType.genericCast(targetType)); + TypeBinding typeCast = originalType.genericCast(targetType); + setGenericCast(length, typeCast); + if (typeCast instanceof ReferenceBinding) { + ReferenceBinding referenceCast = (ReferenceBinding) typeCast; + if (!referenceCast.canBeSeenBy(scope)) { + scope.problemReporter().invalidType(this, + new ProblemReferenceBinding( + CharOperation.splitOn('.', referenceCast.shortReadableName()), + referenceCast, + ProblemReasons.NotVisible)); + } + } } } super.computeConversion(scope, runtimeTimeType, compileTimeType);