8006732: support correct bytecode storage of type annotations in multicatch
Fix issue with annotations being added before attribution, which causes multicatch not to work right and several tests to fail. Reviewed-by: jfranck, jjg
This commit is contained in:
parent
017ea08922
commit
fb5a684124
@ -4096,8 +4096,9 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
|
||||
private static List<Attribute.TypeCompound> fromAnnotations(List<JCAnnotation> annotations) {
|
||||
if (annotations.isEmpty())
|
||||
if (annotations.isEmpty()) {
|
||||
return List.nil();
|
||||
}
|
||||
|
||||
ListBuffer<Attribute.TypeCompound> buf = new ListBuffer<>();
|
||||
for (JCAnnotation anno : annotations) {
|
||||
@ -4109,6 +4110,10 @@ public class Attr extends JCTree.Visitor {
|
||||
// Any better solutions?
|
||||
buf.append((Attribute.TypeCompound) anno.attribute);
|
||||
}
|
||||
// Eventually we will want to throw an exception here, but
|
||||
// we can't do that just yet, because it gets triggered
|
||||
// when attempting to attach an annotation that isn't
|
||||
// defined.
|
||||
}
|
||||
return buf.toList();
|
||||
}
|
||||
|
@ -573,45 +573,51 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
|
||||
Env<AttrContext> localEnv = methodEnv(tree, env);
|
||||
|
||||
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
|
||||
annotate.enterStart();
|
||||
try {
|
||||
// Compute the method type
|
||||
m.type = signature(m, tree.typarams, tree.params,
|
||||
tree.restype, tree.recvparam,
|
||||
tree.thrown,
|
||||
localEnv);
|
||||
} finally {
|
||||
deferredLintHandler.setPos(prevLintPos);
|
||||
}
|
||||
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
|
||||
try {
|
||||
// Compute the method type
|
||||
m.type = signature(m, tree.typarams, tree.params,
|
||||
tree.restype, tree.recvparam,
|
||||
tree.thrown,
|
||||
localEnv);
|
||||
} finally {
|
||||
deferredLintHandler.setPos(prevLintPos);
|
||||
}
|
||||
|
||||
if (types.isSignaturePolymorphic(m)) {
|
||||
m.flags_field |= SIGNATURE_POLYMORPHIC;
|
||||
}
|
||||
if (types.isSignaturePolymorphic(m)) {
|
||||
m.flags_field |= SIGNATURE_POLYMORPHIC;
|
||||
}
|
||||
|
||||
// Set m.params
|
||||
ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
|
||||
JCVariableDecl lastParam = null;
|
||||
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
|
||||
JCVariableDecl param = lastParam = l.head;
|
||||
params.append(Assert.checkNonNull(param.sym));
|
||||
}
|
||||
m.params = params.toList();
|
||||
// Set m.params
|
||||
ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
|
||||
JCVariableDecl lastParam = null;
|
||||
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
|
||||
JCVariableDecl param = lastParam = l.head;
|
||||
params.append(Assert.checkNonNull(param.sym));
|
||||
}
|
||||
m.params = params.toList();
|
||||
|
||||
// mark the method varargs, if necessary
|
||||
if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
|
||||
m.flags_field |= Flags.VARARGS;
|
||||
// mark the method varargs, if necessary
|
||||
if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
|
||||
m.flags_field |= Flags.VARARGS;
|
||||
|
||||
localEnv.info.scope.leave();
|
||||
if (chk.checkUnique(tree.pos(), m, enclScope)) {
|
||||
localEnv.info.scope.leave();
|
||||
if (chk.checkUnique(tree.pos(), m, enclScope)) {
|
||||
enclScope.enter(m);
|
||||
}
|
||||
annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
|
||||
// Visit the signature of the method. Note that
|
||||
// TypeAnnotate doesn't descend into the body.
|
||||
typeAnnotate(tree, localEnv, m, tree.pos());
|
||||
}
|
||||
|
||||
if (tree.defaultValue != null)
|
||||
annotateDefaultValueLater(tree.defaultValue, localEnv, m);
|
||||
annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
|
||||
// Visit the signature of the method. Note that
|
||||
// TypeAnnotate doesn't descend into the body.
|
||||
typeAnnotate(tree, localEnv, m, tree.pos());
|
||||
|
||||
if (tree.defaultValue != null)
|
||||
annotateDefaultValueLater(tree.defaultValue, localEnv, m);
|
||||
} finally {
|
||||
annotate.enterDone();
|
||||
}
|
||||
}
|
||||
|
||||
/** Create a fresh environment for method bodies.
|
||||
@ -639,61 +645,68 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
localEnv.info.staticLevel++;
|
||||
}
|
||||
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(tree.pos());
|
||||
annotate.enterStart();
|
||||
try {
|
||||
if (TreeInfo.isEnumInit(tree)) {
|
||||
attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
|
||||
} else {
|
||||
attr.attribType(tree.vartype, localEnv);
|
||||
if (tree.nameexpr != null) {
|
||||
attr.attribExpr(tree.nameexpr, localEnv);
|
||||
MethodSymbol m = localEnv.enclMethod.sym;
|
||||
if (m.isConstructor()) {
|
||||
Type outertype = m.owner.owner.type;
|
||||
if (outertype.hasTag(TypeTag.CLASS)) {
|
||||
checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
|
||||
checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
|
||||
try {
|
||||
if (TreeInfo.isEnumInit(tree)) {
|
||||
attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype);
|
||||
} else {
|
||||
attr.attribType(tree.vartype, localEnv);
|
||||
if (tree.nameexpr != null) {
|
||||
attr.attribExpr(tree.nameexpr, localEnv);
|
||||
MethodSymbol m = localEnv.enclMethod.sym;
|
||||
if (m.isConstructor()) {
|
||||
Type outertype = m.owner.owner.type;
|
||||
if (outertype.hasTag(TypeTag.CLASS)) {
|
||||
checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
|
||||
checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
|
||||
} else {
|
||||
log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
|
||||
}
|
||||
} else {
|
||||
log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class");
|
||||
checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
|
||||
checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
|
||||
}
|
||||
} else {
|
||||
checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
|
||||
checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
deferredLintHandler.setPos(prevLintPos);
|
||||
}
|
||||
} finally {
|
||||
deferredLintHandler.setPos(prevLintPos);
|
||||
}
|
||||
|
||||
if ((tree.mods.flags & VARARGS) != 0) {
|
||||
//if we are entering a varargs parameter, we need to replace its type
|
||||
//(a plain array type) with the more precise VarargsType --- we need
|
||||
//to do it this way because varargs is represented in the tree as a modifier
|
||||
//on the parameter declaration, and not as a distinct type of array node.
|
||||
ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType();
|
||||
tree.vartype.type = atype.makeVarargs();
|
||||
}
|
||||
Scope enclScope = enter.enterScope(env);
|
||||
VarSymbol v =
|
||||
new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
|
||||
v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
|
||||
tree.sym = v;
|
||||
if (tree.init != null) {
|
||||
v.flags_field |= HASINIT;
|
||||
if ((v.flags_field & FINAL) != 0 &&
|
||||
needsLazyConstValue(tree.init)) {
|
||||
Env<AttrContext> initEnv = getInitEnv(tree, env);
|
||||
initEnv.info.enclVar = v;
|
||||
v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
|
||||
if ((tree.mods.flags & VARARGS) != 0) {
|
||||
//if we are entering a varargs parameter, we need to
|
||||
//replace its type (a plain array type) with the more
|
||||
//precise VarargsType --- we need to do it this way
|
||||
//because varargs is represented in the tree as a
|
||||
//modifier on the parameter declaration, and not as a
|
||||
//distinct type of array node.
|
||||
ArrayType atype = (ArrayType)tree.vartype.type.unannotatedType();
|
||||
tree.vartype.type = atype.makeVarargs();
|
||||
}
|
||||
Scope enclScope = enter.enterScope(env);
|
||||
VarSymbol v =
|
||||
new VarSymbol(0, tree.name, tree.vartype.type, enclScope.owner);
|
||||
v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
|
||||
tree.sym = v;
|
||||
if (tree.init != null) {
|
||||
v.flags_field |= HASINIT;
|
||||
if ((v.flags_field & FINAL) != 0 &&
|
||||
needsLazyConstValue(tree.init)) {
|
||||
Env<AttrContext> initEnv = getInitEnv(tree, env);
|
||||
initEnv.info.enclVar = v;
|
||||
v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
|
||||
}
|
||||
}
|
||||
if (chk.checkUnique(tree.pos(), v, enclScope)) {
|
||||
chk.checkTransparentVar(tree.pos(), v, enclScope);
|
||||
enclScope.enter(v);
|
||||
}
|
||||
annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
|
||||
typeAnnotate(tree.vartype, env, v, tree.pos());
|
||||
v.pos = tree.pos;
|
||||
} finally {
|
||||
annotate.enterDone();
|
||||
}
|
||||
if (chk.checkUnique(tree.pos(), v, enclScope)) {
|
||||
chk.checkTransparentVar(tree.pos(), v, enclScope);
|
||||
enclScope.enter(v);
|
||||
}
|
||||
annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
|
||||
typeAnnotate(tree.vartype, env, v, tree.pos());
|
||||
v.pos = tree.pos;
|
||||
}
|
||||
// where
|
||||
void checkType(JCTree tree, Type type, String diag) {
|
||||
|
@ -1652,9 +1652,10 @@ public class Gen extends JCTree.Visitor {
|
||||
startpc, end, code.curCP(),
|
||||
catchType);
|
||||
if (subCatch.type.isAnnotated()) {
|
||||
// All compounds share the same position, simply update the
|
||||
// first one.
|
||||
subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
|
||||
for (Attribute.TypeCompound tc :
|
||||
subCatch.type.getAnnotationMirrors()) {
|
||||
tc.position.type_index = catchType;
|
||||
}
|
||||
}
|
||||
}
|
||||
gaps = gaps.tail;
|
||||
@ -1668,9 +1669,10 @@ public class Gen extends JCTree.Visitor {
|
||||
startpc, endpc, code.curCP(),
|
||||
catchType);
|
||||
if (subCatch.type.isAnnotated()) {
|
||||
// All compounds share the same position, simply update the
|
||||
// first one.
|
||||
subCatch.type.getAnnotationMirrors().head.position.type_index = catchType;
|
||||
for (Attribute.TypeCompound tc :
|
||||
subCatch.type.getAnnotationMirrors()) {
|
||||
tc.position.type_index = catchType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* @bug 8006733 8006775
|
||||
* @summary Ensure behavior for nested types is correct.
|
||||
* @author Werner Dietl
|
||||
* @ignore
|
||||
* @compile/fail/ref=CantAnnotateStaticClass2.out -XDrawDiagnostics CantAnnotateStaticClass2.java
|
||||
*/
|
||||
|
||||
|
@ -24,10 +24,6 @@ CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1:
|
||||
CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:128:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
@ -50,6 +46,10 @@ CantAnnotateStaticClass2.java:165:22: compiler.err.cant.type.annotate.scoping.1:
|
||||
CantAnnotateStaticClass2.java:167:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:169:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:171:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:184:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:186:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:187:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
@ -62,4 +62,4 @@ CantAnnotateStaticClass2.java:201:41: compiler.err.cant.type.annotate.scoping.1:
|
||||
CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB
|
||||
CantAnnotateStaticClass2.java:204:49: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC
|
||||
64 errors
|
||||
64 errors
|
||||
|
@ -25,7 +25,6 @@ import java.lang.annotation.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @ignore 8008762 Type annotations failures
|
||||
* @bug 8006775
|
||||
* @summary new type annotation location: multicatch
|
||||
* @author Werner Dietl
|
||||
|
@ -25,7 +25,6 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @ignore 8008762 Type annotation failures
|
||||
* @bug 8006732 8006775
|
||||
* @summary Test population of reference info for multicatch exception parameters
|
||||
* @author Werner Dietl
|
||||
|
Loading…
x
Reference in New Issue
Block a user