Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8264216: [lworld] unknown.Class.default gives misleading compilation error #372

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok, inventing a new error message altogether (such as default cannot be applied to a package) looks too heavy a hammer.

case ERROR -> types.createErrorType(names._default, site.tsym, site).tsym;
default -> new VarSymbol(STATIC, names._default, site, site.tsym);
};
Expand Down
@@ -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
jespersm marked this conversation as resolved.
Show resolved Hide resolved