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

Suspicious check in Resolver.findClassInPackage #3018

Closed
michaelhixson opened this issue Dec 26, 2019 · 0 comments · Fixed by #3031
Closed

Suspicious check in Resolver.findClassInPackage #3018

michaelhixson opened this issue Dec 26, 2019 · 0 comments · Fixed by #3031
Assignees

Comments

@michaelhixson
Copy link
Contributor

Document or fix this suspicious-looking element kind check in Resolver.findClassInPackage.

Element res =
wrapInvocationOnResolveInstance(
FIND_IDENT_IN_PACKAGE,
env,
pck,
names.fromString(name),
Kinds.KindSelector.TYP);
if (res.getKind() == ElementKind.CLASS) {
return (ClassSymbol) res;
} else {
return null;
}

Why does it check for exactly ElementKind.CLASS? Why doesn't it do something like this instead?

if (res.getKind().isClass() || res.getKind().isInterface()) {
    return (ClassSymbol) res;
} else {
    return null;
}

Its only caller is in FlowExpressionParseUtil.

ClassSymbol classSymbol =
resolver.findClassInPackage(expr.getNameAsString(), packageSymbol, path);
if (classSymbol != null) {
return new ClassName(classSymbol.asType());
}

It's not clear why that code would not want to find the class if the class was an enum, for example. If there's a reason for this, then perhaps an inline comment should be added to state that reason.

I'm filing this issue because @wmdietl asked me to in #3017.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants