Skip to content

Commit

Permalink
8211004: javac is complaining about non-denotable types and refusing …
Browse files Browse the repository at this point in the history
…to generate the class file

Reviewed-by: jlahoda
  • Loading branch information
Vicente Romero committed Jan 6, 2022
1 parent 844dfb3 commit 456bd1e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
import com.sun.tools.javac.comp.MatchBindingsComputer.MatchBindings;
import com.sun.tools.javac.jvm.*;

import static com.sun.tools.javac.resources.CompilerProperties.Fragments.Diamond;
import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArg;
import static com.sun.tools.javac.resources.CompilerProperties.Fragments.DiamondInvalidArgs;

import com.sun.tools.javac.resources.CompilerProperties.Errors;
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
import com.sun.tools.javac.resources.CompilerProperties.Warnings;
Expand Down Expand Up @@ -2909,6 +2911,12 @@ private void visitAnonymousClassDefinition(JCNewClass tree, JCExpression clazz,
// ...
// }
InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext();
Type enclType = clazztype.getEnclosingType();
if (enclType != null &&
enclType.hasTag(CLASS) &&
!chk.checkDenotable((ClassType)enclType)) {
log.error(tree.encl, Errors.EnclosingClassTypeNonDenotable(enclType));
}
final boolean isDiamond = TreeInfo.isDiamond(tree);
if (isDiamond
&& ((tree.constructorType != null && inferenceContext.free(tree.constructorType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3912,3 +3912,8 @@ compiler.warn.declared.using.preview=\

compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class=\
attempt to synchronize on an instance of a value-based class

# 0: type
compiler.err.enclosing.class.type.non.denotable=\
enclosing class type: {0}\n\
is non-denotable, try casting to a denotable type
2 changes: 1 addition & 1 deletion test/langtools/tools/javac/8203436/T8203436a.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
* @bug 8203436
* @bug 8203436 8211004
* @summary javac should fail early when emitting illegal signature attributes
* @compile/fail/ref=T8203436a.out -XDrawDiagnostics T8203436a.java
*/
Expand Down
2 changes: 1 addition & 1 deletion test/langtools/tools/javac/8203436/T8203436a.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- compiler.err.cannot.generate.class: compiler.misc.anonymous.class: T8203436a$1, (compiler.misc.illegal.signature: compiler.misc.anonymous.class: T8203436a$1, compiler.misc.type.captureof: 1, ?)
T8203436a.java:12:7: compiler.err.enclosing.class.type.non.denotable: T8203436a<compiler.misc.type.captureof: 1, ?>
1 error
2 changes: 1 addition & 1 deletion test/langtools/tools/javac/8203436/T8203436b.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- compiler.err.cannot.generate.class: compiler.misc.anonymous.class: T8203436b$1, (compiler.misc.illegal.signature: compiler.misc.anonymous.class: T8203436b$1, java.lang.Object&T8203436b.A&T8203436b.B)
T8203436b.java:17:10: compiler.err.enclosing.class.type.non.denotable: T8203436b<java.lang.Object&T8203436b.A&T8203436b.B>
1 error
1 change: 1 addition & 0 deletions test/langtools/tools/javac/diags/examples.not-yet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,4 @@ compiler.warn.source.target.conflict
compiler.warn.target.default.source.conflict
compiler.err.preview.not.latest
compiler.err.preview.without.source.or.release
compiler.misc.illegal.signature # the compiler can now detect more non-denotable types before class writing
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
* questions.
*/

// key: compiler.err.cannot.generate.class
// key: compiler.misc.illegal.signature
// key: compiler.err.enclosing.class.type.non.denotable

class IllegalSignature<X> {
class Inner { }
Expand Down
3 changes: 2 additions & 1 deletion test/langtools/tools/javac/generics/diamond/neg/Neg21.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Neg21.java:13:9: compiler.err.enclosing.class.type.non.denotable: Neg21<java.lang.Object&java.io.Serializable&java.lang.Cloneable>
Neg21.java:13:28: compiler.err.cant.apply.diamond.1: (compiler.misc.diamond: Neg21.A), (compiler.misc.diamond.invalid.arg: java.lang.Object&java.io.Serializable&java.lang.Cloneable, (compiler.misc.diamond: Neg21.A))
1 error
2 errors

0 comments on commit 456bd1e

Please sign in to comment.