Skip to content
Permalink
Browse files
8264216: [lworld] unknown.Class.default gives misleading compilation …
…error

Reviewed-by: sadayapalam
  • Loading branch information
Jesper Steen Møller authored and Srikanth Adayapalam committed Apr 1, 2021
1 parent 83d849f commit 28a4ec0249fd86fe17f2b816c6f5f8eed31abfeb
@@ -4888,12 +4888,17 @@ public void visitDefaultValue(JCDefaultValue tree) {
}

// Attribute the qualifier expression, and determine its symbol (if any).
Type site = attribTree(tree.clazz, env, new ResultInfo(KindSelector.TYP, Type.noType));
Type site = attribTree(tree.clazz, env, new ResultInfo(KindSelector.TYP_PCK, Type.noType));
if (!pkind().contains(KindSelector.TYP_PCK))
site = capture(site); // Capture field access

Symbol sym = switch (site.getTag()) {
case PACKAGE, WILDCARD -> throw new AssertionError(tree);
case WILDCARD -> throw new AssertionError(tree);
case PACKAGE -> {
log.error(tree.pos, Errors.CantResolveLocation(Kinds.KindName.CLASS, site.tsym.getQualifiedName(), null, null,
Fragments.Location(Kinds.typeKindName(env.enclClass.type), env.enclClass.type, null)));
yield syms.errSymbol;
}
case ERROR -> types.createErrorType(names._default, site.tsym, site).tsym;
default -> new VarSymbol(STATIC, names._default, site, site.tsym);
};
@@ -0,0 +1,14 @@
/*
* @test /nodynamiccopyright/
* @bug 8264216
* @summary [lworld] unknown.Class.default gives misleading compilation error
* @compile/fail/ref=UnknownTypeDefault.out -Xlint:all -Werror -XDrawDiagnostics -XDdev UnknownTypeDefault.java
*/

public class UnknownTypeDefault {

public static void main(String [] args) {
Object d1 = Y.default;
Object d2 = y.Z.default;
}
}
@@ -0,0 +1,3 @@
UnknownTypeDefault.java:11:22: compiler.err.cant.resolve.location: kindname.class, Y, null, null, (compiler.misc.location: kindname.class, UnknownTypeDefault, null)
UnknownTypeDefault.java:12:24: compiler.err.cant.resolve.location: kindname.class, y.Z, null, null, (compiler.misc.location: kindname.class, UnknownTypeDefault, null)
2 errors

0 comments on commit 28a4ec0

Please sign in to comment.