提交 28ae8e1f 编写于 作者: M mcimadamore

7020043: Project Coin: diamond allowed on non-generic type

Summary: Diamond oerator should be disallowed on non-generic class types (i.e. String)
Reviewed-by: jjg
上级 3ebe5cea
......@@ -1584,6 +1584,11 @@ public class Attr extends JCTree.Visitor {
if (!TreeInfo.isDiamond(tree)) {
clazztype = chk.checkClassType(
tree.clazz.pos(), clazztype, true);
} else if (!clazztype.isErroneous() &&
!clazztype.tsym.type.isParameterized()) {
log.error(tree.clazz.pos(),
"cant.apply.diamond.1",
clazztype, diags.fragment("diamond.non.generic", clazztype));
}
chk.validate(clazz, localEnv);
if (tree.encl != null) {
......@@ -1609,7 +1614,7 @@ public class Attr extends JCTree.Visitor {
List<Type> argtypes = attribArgs(tree.args, localEnv);
List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv);
if (TreeInfo.isDiamond(tree)) {
if (TreeInfo.isDiamond(tree) && clazztype.tsym.type.isParameterized()) {
clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes);
clazz.type = clazztype;
} else if (allowDiamondFinder &&
......
......@@ -1584,6 +1584,10 @@ compiler.misc.inferred.do.not.conform.to.bounds=\
compiler.misc.diamond=\
{0}<>
# 0: type
compiler.misc.diamond.non.generic=\
cannot use ''<>'' with non-generic class {0}
# 0: list of type, 1: message segment
compiler.misc.diamond.invalid.arg=\
type argument {0} inferred for {1} is not allowed in this context
......
/*
* @test /nodynamiccopyright/
* @bug 7020043
*
* @summary Project Coin: diamond allowed on non-generic type
* @author R&eacute;mi Forax
* @compile/fail/ref=Neg12.out Neg12.java -XDrawDiagnostics
*
*/
class DiamondRaw {
public static void main(String[] args) {
String s = new String<>("foo");
}
}
Neg12.java:13:27: compiler.err.cant.apply.diamond.1: java.lang.String, (compiler.misc.diamond.non.generic: java.lang.String)
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册