提交 8d61fb1f 编写于 作者: M mcimadamore

6730476: invalid "unchecked generic array" warning

Summary: Reifiable-ness of varargs element type should be checked after JLS3 15.12.2.8
Reviewed-by: jjg
上级 580a89f0
......@@ -2621,12 +2621,10 @@ public class Attr extends JCTree.Visitor {
}
if (useVarargs) {
JCTree tree = env.tree;
Type argtype = owntype.getParameterTypes().last();
if (!types.isReifiable(argtype))
chk.warnUnchecked(env.tree.pos(),
"unchecked.generic.array.creation",
argtype);
Type elemtype = types.elemtype(argtype);
if (owntype.getReturnType().tag != FORALL || warned) {
chk.checkVararg(env.tree.pos(), owntype.getParameterTypes());
}
Type elemtype = types.elemtype(owntype.getParameterTypes().last());
switch (tree.getTag()) {
case JCTree.APPLY:
((JCMethodInvocation) tree).varargsElement = elemtype;
......
......@@ -677,6 +677,19 @@ public class Check {
}
}
/**
* Check that vararg method call is sound
* @param pos Position to be used for error reporting.
* @param argtypes Actual arguments supplied to vararg method.
*/
void checkVararg(DiagnosticPosition pos, List<Type> argtypes) {
Type argtype = argtypes.last();
if (!types.isReifiable(argtype))
warnUnchecked(pos,
"unchecked.generic.array.creation",
argtype);
}
/** Check that given modifiers are legal for given symbol and
* return modifiers together with any implicit modififiers for that symbol.
* Warning: we can't use flags() here since this method
......
......@@ -287,7 +287,8 @@ public class Infer {
/** Instantiate method type `mt' by finding instantiations of
* `tvars' so that method can be applied to `argtypes'.
*/
public Type instantiateMethod(List<Type> tvars,
public Type instantiateMethod(final Env<AttrContext> env,
List<Type> tvars,
MethodType mt,
final List<Type> argtypes,
final boolean allowBoxing,
......@@ -416,6 +417,9 @@ public class Infer {
// check that inferred bounds conform to their bounds
checkWithinBounds(all_tvars,
types.subst(inferredTypes, tvars, inferred), warn);
if (useVarargs) {
chk.checkVararg(env.tree.pos(), formals);
}
return super.inst(inferred, types);
}};
return mt2;
......
......@@ -345,7 +345,8 @@ public class Resolve {
if (instNeeded)
return
infer.instantiateMethod(tvars,
infer.instantiateMethod(env,
tvars,
(MethodType)mt,
argtypes,
allowBoxing,
......
/*
* Copyright 2010 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
* @bug 6730476
*
* @summary invalid "unchecked generic array" warning
* @author mcimadamore
* @compile T6730476a.java -Xlint -Werror
*
*/
class T6730476a {
<T> void f(int i, T ... x) {}
void g() {
f(1);
}
}
/*
* Copyright 2010 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
* @bug 6730476
*
* @summary invalid "unchecked generic array" warning
* @author mcimadamore
* @compile T6730476b.java -Xlint -Werror
*
*/
class T6730476b {
java.util.List<Integer> ints = java.util.Arrays.asList();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册