Mercurial > hg > openjdk > jdk8u > langtools
changeset 880:4ce95dc0b908
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
author | mcimadamore |
---|---|
date | Fri, 18 Feb 2011 12:28:49 +0000 |
parents | 0c24826853b2 |
children | 3d45cc94ee0f |
files | src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/resources/compiler.properties test/tools/javac/generics/diamond/neg/Neg12.java test/tools/javac/generics/diamond/neg/Neg12.out |
diffstat | 4 files changed, 27 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Feb 16 10:27:00 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Feb 18 12:28:49 2011 +0000 @@ -1584,6 +1584,11 @@ 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 @@ 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 &&
--- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Feb 16 10:27:00 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Feb 18 12:28:49 2011 +0000 @@ -1584,6 +1584,10 @@ 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/neg/Neg12.java Fri Feb 18 12:28:49 2011 +0000 @@ -0,0 +1,15 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7020043 + * + * @summary Project Coin: diamond allowed on non-generic type + * @author Rémi Forax + * @compile/fail/ref=Neg12.out Neg12.java -XDrawDiagnostics + * + */ + +class DiamondRaw { + public static void main(String[] args) { + String s = new String<>("foo"); + } +}