# HG changeset patch # User mcimadamore # Date 1231853300 0 # Node ID 7182011ee8a659149b9c8c1ff0d2f3acfb9d535e # Parent 7ac8c0815000ea09bfac6bb5f87a7ddae341f59e 6665356: Cast not allowed when both qualifying type and inner class are parameterized Summary: Fixed parser and cats conversion in order to allow cast between generic inner classes Reviewed-by: jjg diff -r 7ac8c0815000 -r 7182011ee8a6 langtools/src/share/classes/com/sun/tools/javac/code/Types.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Tue Jan 13 13:27:14 2009 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Tue Jan 13 13:28:20 2009 +0000 @@ -880,12 +880,12 @@ if (warn != warnStack.head) { try { warnStack = warnStack.prepend(warn); - return isCastable.visit(t, s); + return isCastable.visit(t,s); } finally { warnStack = warnStack.tail; } } else { - return isCastable.visit(t, s); + return isCastable.visit(t,s); } } // where @@ -983,10 +983,10 @@ if (highSub != null) { assert a.tsym == highSub.tsym && a.tsym == lowSub.tsym : a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym; - if (!disjointTypes(aHigh.getTypeArguments(), highSub.getTypeArguments()) - && !disjointTypes(aHigh.getTypeArguments(), lowSub.getTypeArguments()) - && !disjointTypes(aLow.getTypeArguments(), highSub.getTypeArguments()) - && !disjointTypes(aLow.getTypeArguments(), lowSub.getTypeArguments())) { + if (!disjointTypes(aHigh.allparams(), highSub.allparams()) + && !disjointTypes(aHigh.allparams(), lowSub.allparams()) + && !disjointTypes(aLow.allparams(), highSub.allparams()) + && !disjointTypes(aLow.allparams(), lowSub.allparams())) { if (upcast ? giveWarning(a, highSub) || giveWarning(a, lowSub) : giveWarning(highSub, a) || giveWarning(lowSub, a)) warnStack.head.warnUnchecked(); @@ -1197,6 +1197,7 @@ s = upperBound(s); if (s.tag == TYPEVAR) s = s.getUpperBound(); + return !isSubtype(t, s); } // @@ -3189,7 +3190,7 @@ private boolean giveWarning(Type from, Type to) { // To and from are (possibly different) parameterizations // of the same class or interface - return to.isParameterized() && !containsType(to.getTypeArguments(), from.getTypeArguments()); + return to.isParameterized() && !containsType(to.allparams(), from.allparams()); } private List superClosure(Type t, Type s) { diff -r 7ac8c0815000 -r 7182011ee8a6 langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Jan 13 13:27:14 2009 +0000 +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Jan 13 13:28:20 2009 +0000 @@ -864,6 +864,12 @@ t = F.at(pos1).TypeApply(t, args.toList()); checkGenerics(); t = bracketsOpt(toP(t)); + while (S.token() == DOT) { + S.nextToken(); + mode = TYPE; + t = toP(F.at(S.pos()).Select(t, ident())); + t = typeArgumentsOpt(t); + } } else if ((mode & EXPR) != 0) { mode = EXPR; t = F.at(pos1).Binary(op, t, term2Rest(t1, TreeInfo.shiftPrec)); @@ -871,7 +877,8 @@ } else { accept(GT); } - } else { + } + else { t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec))); } accept(RPAREN); diff -r 7ac8c0815000 -r 7182011ee8a6 langtools/test/tools/javac/cast/6665356/T6665356.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/cast/6665356/T6665356.java Tue Jan 13 13:28:20 2009 +0000 @@ -0,0 +1,80 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @author Maurizio Cimadamore + * @bug 6665356 + * @summary Cast not allowed when both qualifying type and inner class are parameterized + * @compile/fail/ref=T6665356.out -XDrawDiagnostics T6665356.java + */ + +class T6665356 { + class Outer { + class Inner {} + } + + void cast1(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast2(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast3(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast4(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast5(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast6(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast7(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast8(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast9(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast10(Outer.Inner p) { + Object o = (Outer.Inner)p; + } + + void cast11(Outer.Inner p) { + Object o = (Outer.Inner)p; + } +} \ No newline at end of file diff -r 7ac8c0815000 -r 7182011ee8a6 langtools/test/tools/javac/cast/6665356/T6665356.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/cast/6665356/T6665356.out Tue Jan 13 13:28:20 2009 +0000 @@ -0,0 +1,8 @@ +T6665356.java:54:55: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +T6665356.java:58:58: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +T6665356.java:62:65: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +T6665356.java:66:57: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +T6665356.java:70:60: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +T6665356.java:74:55: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +T6665356.java:78:58: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer.Inner, T6665356.Outer.Inner +7 errors \ No newline at end of file diff -r 7ac8c0815000 -r 7182011ee8a6 langtools/test/tools/javac/generics/rare/6665356/T6665356.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/rare/6665356/T6665356.java Tue Jan 13 13:28:20 2009 +0000 @@ -0,0 +1,53 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @author Maurizio Cimadamore + * @bug 6665356 + * @summary Cast not allowed when both qualifying type and inner class are parameterized + * @compile/fail/ref=T6665356.out -XDrawDiagnostics T6665356.java + */ + +class T6665356 { + class Outer { + class Inner {} + } + + void test1() { + boolean b; + b = null instanceof Outer.Inner; + b = null instanceof Outer.Inner; + b = null instanceof Outer.Inner; + b = null instanceof Outer.Inner; + } + + void test2() { + boolean b; + Object o; + o = (Outer.Inner)null; + o = (Outer.Inner)null; + o = (Outer.Inner)null; + o = (Outer.Inner)null; + } +} \ No newline at end of file diff -r 7ac8c0815000 -r 7182011ee8a6 langtools/test/tools/javac/generics/rare/6665356/T6665356.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/generics/rare/6665356/T6665356.out Tue Jan 13 13:28:20 2009 +0000 @@ -0,0 +1,5 @@ +T6665356.java:40:37: compiler.err.improperly.formed.type.param.missing +T6665356.java:41:40: compiler.err.improperly.formed.type.inner.raw.param +T6665356.java:49:23: compiler.err.improperly.formed.type.param.missing +T6665356.java:50:25: compiler.err.improperly.formed.type.inner.raw.param +4 errors \ No newline at end of file