8026374: javac accepts void as a method parameter
Changing Check.validate to reject void types. Reviewed-by: jjg, vromero
This commit is contained in:
parent
979151dfa9
commit
38ef229e3f
langtools
src/share/classes/com/sun/tools/javac/comp
test/tools/javac/declaration/method
@ -933,7 +933,8 @@ public class Attr extends JCTree.Visitor {
|
||||
chk.validate(tree.typarams, localEnv);
|
||||
|
||||
// Check that result type is well-formed.
|
||||
chk.validate(tree.restype, localEnv);
|
||||
if (tree.restype != null && !tree.restype.type.hasTag(VOID))
|
||||
chk.validate(tree.restype, localEnv);
|
||||
|
||||
// Check that receiver type is well-formed.
|
||||
if (tree.recvparam != null) {
|
||||
|
@ -1326,6 +1326,14 @@ public class Check {
|
||||
tree.underlyingType.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitTypeIdent(JCPrimitiveTypeTree that) {
|
||||
if (that.type.hasTag(TypeTag.VOID)) {
|
||||
log.error(that.pos(), "void.not.allowed.here");
|
||||
}
|
||||
super.visitTypeIdent(that);
|
||||
}
|
||||
|
||||
/** Default visitor method: do nothing.
|
||||
*/
|
||||
@Override
|
||||
|
@ -0,0 +1,9 @@
|
||||
/* @test /nodynamiccopyright/
|
||||
* @bug 8026374
|
||||
* @summary Cannot use void as a variable type
|
||||
* @compile/fail/ref=MethodVoidParameter.out -XDrawDiagnostics MethodVoidParameter.java
|
||||
*/
|
||||
public class MethodVoidParameter {
|
||||
void method(void v) { }
|
||||
void method(void... v) { }
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
MethodVoidParameter.java:7:17: compiler.err.void.not.allowed.here
|
||||
MethodVoidParameter.java:8:17: compiler.err.void.not.allowed.here
|
||||
2 errors
|
Loading…
x
Reference in New Issue
Block a user