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

identifier not found, pattern variable with instanceof #5240

Closed
potjerodekool opened this issue Aug 4, 2022 · 1 comment · Fixed by #5243
Closed

identifier not found, pattern variable with instanceof #5240

potjerodekool opened this issue Aug 4, 2022 · 1 comment · Fixed by #5243

Comments

@potjerodekool
Copy link

Using checkerframework vesion 3.24.0 with Java 17

The following code:

import org.checkerframework.checker.nullness.qual.KeyFor;

import java.util.List;
import java.util.Map;

public class PatternVariableDemo {

    public void doSomething(final Type type) {
        if (type instanceof ClassOrInterfaceType ct) {
            //final var ct = (ClassOrInterfaceType) type;

            List<Map.Entry<@KeyFor("ct.getFields()") String, Field>> finalFields = ct.getFields().entrySet().stream()
                    .filter(entry -> entry.getValue().getModifiers().contains(Modifier.FINAL))
                    .toList();
        }
    }
}

Results in the following error:

error: [expression.unparsable] Expression invalid in dependent type annotation: [error for expression: ct.getFields(); error: Invalid 'ct' because identifier not found]

A workaround is not using a pattern variable.

mernst added a commit to mernst/checker-framework that referenced this issue Aug 4, 2022
@mernst mernst linked a pull request Aug 5, 2022 that will close this issue
@mernst
Copy link
Member

mernst commented Aug 5, 2022

Thanks for the bug report. There were some new enum constants that were not being checked.

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

Successfully merging a pull request may close this issue.

2 participants