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

In JSpecify mode, reason about array contents nullability in for-each loop over array #983

Closed
msridhar opened this issue Jun 19, 2024 · 0 comments · Fixed by #986
Closed
Assignees
Labels
jspecify Related to support for jspecify standard (see jspecify.dev)

Comments

@msridhar
Copy link
Collaborator

See test case forEachLoop() in #982. We don't properly reason that when the array contents are @Nullable the for-each loop variable is @Nullable.

@msridhar msridhar added the jspecify Related to support for jspecify standard (see jspecify.dev) label Jun 19, 2024
msridhar pushed a commit that referenced this issue Jun 22, 2024
…986)

Currently, enhanced-for-loops do not honor nullability annotations on
arrays.

**Current Behavior**
Both these dereferences work fine.
```
static @nullable String[] fizz = {"1"}
for (String s: fizz){
     s.toString();
     if (s!=null){
          s.toString();
     }  
}

```
**New Behavior**
The first one throws an error, as expected.
```
static @nullable String[] fizz = {"1"}
for (String s: fizz){
     // BUG: Diagnostic contains: dereferenced expression s is @nullable
     s.toString();
     if (s!=null){
          s.toString();
     }  
}

```



Fixes #983
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jspecify Related to support for jspecify standard (see jspecify.dev)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants