提交 c3de5b2a 编写于 作者: M mcimadamore

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
上级 fd1502a0
......@@ -880,12 +880,12 @@ public class Types {
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 @@ public class Types {
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 @@ public class Types {
s = upperBound(s);
if (s.tag == TYPEVAR)
s = s.getUpperBound();
return !isSubtype(t, s);
}
// </editor-fold>
......@@ -3189,7 +3190,7 @@ public class Types {
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<Type> superClosure(Type t, Type s) {
......
......@@ -864,6 +864,12 @@ public class JavacParser implements Parser {
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 @@ public class JavacParser implements Parser {
} else {
accept(GT);
}
} else {
}
else {
t = termRest(term1Rest(term2Rest(t, TreeInfo.orPrec)));
}
accept(RPAREN);
......
/*
* 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<S> {
class Inner<T> {}
}
void cast1(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<Integer>.Inner<Long>)p;
}
void cast2(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<? extends Number>.Inner<Long>)p;
}
void cast3(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<Integer>.Inner<? extends Number>)p;
}
void cast4(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<? extends Number>.Inner<? extends Number>)p;
}
void cast5(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<? super Number>.Inner<Long>)p;
}
void cast6(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<Integer>.Inner<? super Number>)p;
}
void cast7(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<? super Number>.Inner<? super Number>)p;
}
void cast8(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<? extends String>.Inner<Long>)p;
}
void cast9(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<Integer>.Inner<? extends String>)p;
}
void cast10(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<? super String>.Inner<Long>)p;
}
void cast11(Outer<Integer>.Inner<Long> p) {
Object o = (Outer<Integer>.Inner<? super String>)p;
}
}
\ No newline at end of file
T6665356.java:54:55: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<? super java.lang.Number>.Inner<java.lang.Long>
T6665356.java:58:58: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<java.lang.Integer>.Inner<? super java.lang.Number>
T6665356.java:62:65: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<? super java.lang.Number>.Inner<? super java.lang.Number>
T6665356.java:66:57: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<? extends java.lang.String>.Inner<java.lang.Long>
T6665356.java:70:60: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<java.lang.Integer>.Inner<? extends java.lang.String>
T6665356.java:74:55: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<? super java.lang.String>.Inner<java.lang.Long>
T6665356.java:78:58: compiler.err.prob.found.req: (- compiler.misc.inconvertible.types), T6665356.Outer<java.lang.Integer>.Inner<java.lang.Long>, T6665356.Outer<java.lang.Integer>.Inner<? super java.lang.String>
7 errors
\ No newline at end of file
/*
* 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<S> {
class Inner<T> {}
}
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
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册