8338678: Erroneous parameterized type represented as <any>
Reviewed-by: vromero
This commit is contained in:
parent
0b4a7d5342
commit
ff59532ddd
@ -2338,7 +2338,7 @@ public abstract class Type extends AnnoConstruct implements TypeMirror, PoolCons
|
||||
this.originalType = (originalType == null ? noType : originalType);
|
||||
}
|
||||
|
||||
private ErrorType(Type originalType, TypeSymbol tsym,
|
||||
public ErrorType(Type originalType, TypeSymbol tsym,
|
||||
List<TypeMetadata> metadata) {
|
||||
super(noType, List.nil(), null, metadata);
|
||||
this.tsym = tsym;
|
||||
@ -2393,10 +2393,6 @@ public abstract class Type extends AnnoConstruct implements TypeMirror, PoolCons
|
||||
public boolean isCompound() { return false; }
|
||||
public boolean isInterface() { return false; }
|
||||
|
||||
public List<Type> allparams() { return List.nil(); }
|
||||
@DefinedBy(Api.LANGUAGE_MODEL)
|
||||
public List<Type> getTypeArguments() { return List.nil(); }
|
||||
|
||||
@DefinedBy(Api.LANGUAGE_MODEL)
|
||||
public TypeKind getKind() {
|
||||
return TypeKind.ERROR;
|
||||
|
@ -5081,6 +5081,14 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
owntype = types.createErrorType(tree.type);
|
||||
}
|
||||
} else if (clazztype.hasTag(ERROR)) {
|
||||
ErrorType parameterizedErroneous =
|
||||
new ErrorType(clazztype.getOriginalType(),
|
||||
clazztype.tsym,
|
||||
clazztype.getMetadata());
|
||||
|
||||
parameterizedErroneous.typarams_field = actuals;
|
||||
owntype = parameterizedErroneous;
|
||||
}
|
||||
result = check(tree, owntype, KindSelector.TYP, resultInfo);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8301580 8322159 8333107 8332230
|
||||
* @bug 8301580 8322159 8333107 8332230 8338678
|
||||
* @summary Verify error recovery w.r.t. Attr
|
||||
* @library /tools/lib
|
||||
* @enablePreview
|
||||
@ -34,9 +34,23 @@
|
||||
* @run main AttrRecovery
|
||||
*/
|
||||
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import com.sun.source.util.TaskEvent;
|
||||
import com.sun.source.util.TaskListener;
|
||||
import com.sun.source.util.TreePathScanner;
|
||||
import com.sun.source.util.Trees;
|
||||
import java.nio.file.Path;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import toolbox.JavacTask;
|
||||
import toolbox.Task.Expect;
|
||||
@ -234,4 +248,80 @@ public class AttrRecovery extends TestRunner {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizedErroneousType() throws Exception {
|
||||
String code = """
|
||||
public class C {
|
||||
Undefined1<Undefined2, Undefined3> variable1;
|
||||
}
|
||||
""";
|
||||
Path curPath = Path.of(".");
|
||||
List<String> actual = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics")
|
||||
.sources(code)
|
||||
.outdir(curPath)
|
||||
.callback(task -> {
|
||||
task.addTaskListener(new TaskListener() {
|
||||
@Override
|
||||
public void finished(TaskEvent e) {
|
||||
Trees trees = Trees.instance(task);
|
||||
|
||||
if (e.getKind() == TaskEvent.Kind.ANALYZE) {
|
||||
new TreePathScanner<Void, Void>() {
|
||||
@Override
|
||||
public Void visitVariable(VariableTree tree, Void p) {
|
||||
VariableElement var = (VariableElement) trees.getElement(getCurrentPath());
|
||||
|
||||
trees.printMessage(Diagnostic.Kind.NOTE, type2String(var.asType()), tree, e.getCompilationUnit());
|
||||
|
||||
return super.visitVariable(tree, p);
|
||||
}
|
||||
}.scan(e.getCompilationUnit(), null);
|
||||
}
|
||||
}
|
||||
Map<Element, Integer> identityRename = new IdentityHashMap<>();
|
||||
String type2String(TypeMirror type) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
result.append(type.getKind());
|
||||
result.append(":");
|
||||
result.append(type.toString());
|
||||
|
||||
if (type.getKind() == TypeKind.DECLARED ||
|
||||
type.getKind() == TypeKind.ERROR) {
|
||||
DeclaredType dt = (DeclaredType) type;
|
||||
Element el = task.getTypes().asElement(dt);
|
||||
result.append(":");
|
||||
result.append(el.toString());
|
||||
if (!dt.getTypeArguments().isEmpty()) {
|
||||
result.append(dt.getTypeArguments()
|
||||
.stream()
|
||||
.map(tm -> type2String(tm))
|
||||
.collect(Collectors.joining(", ", "<", ">")));
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError(type.getKind().name());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
});
|
||||
})
|
||||
.run(Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(OutputKind.DIRECT);
|
||||
|
||||
List<String> expected = List.of(
|
||||
"C.java:2:5: compiler.err.cant.resolve.location: kindname.class, Undefined1, , , (compiler.misc.location: kindname.class, C, null)",
|
||||
"C.java:2:16: compiler.err.cant.resolve.location: kindname.class, Undefined2, , , (compiler.misc.location: kindname.class, C, null)",
|
||||
"C.java:2:28: compiler.err.cant.resolve.location: kindname.class, Undefined3, , , (compiler.misc.location: kindname.class, C, null)",
|
||||
"C.java:2:40: compiler.note.proc.messager: ERROR:Undefined1<Undefined2,Undefined3>:Undefined1<ERROR:Undefined2:Undefined2, ERROR:Undefined3:Undefined3>",
|
||||
"3 errors"
|
||||
);
|
||||
|
||||
if (!Objects.equals(actual, expected)) {
|
||||
error("Expected: " + expected + ", but got: " + actual);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user