7020043: Project Coin: diamond allowed on non-generic type
Diamond oerator should be disallowed on non-generic class types (i.e. String) Reviewed-by: jjg
This commit is contained in:
parent
f1181c706c
commit
7d8c3e9460
@ -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
|
||||
|
15
langtools/test/tools/javac/generics/diamond/neg/Neg12.java
Normal file
15
langtools/test/tools/javac/generics/diamond/neg/Neg12.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
Neg12.java:13:27: compiler.err.cant.apply.diamond.1: java.lang.String, (compiler.misc.diamond.non.generic: java.lang.String)
|
||||
1 error
|
Loading…
x
Reference in New Issue
Block a user