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

PolyNull and conditional expressions #519

Closed
wmdietl opened this issue Jun 26, 2023 · 1 comment · Fixed by #525
Closed

PolyNull and conditional expressions #519

wmdietl opened this issue Jun 26, 2023 · 1 comment · Fixed by #525

Comments

@wmdietl
Copy link
Member

wmdietl commented Jun 26, 2023

Take this code:

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

class Demo {
    public static @PolyNull String toLowerCaseA(@PolyNull String text) {
        return text == null ? null : text.toLowerCase();
    }
    public static @PolyNull String toLowerCaseB(@PolyNull String text) {
        return text != null ? text.toLowerCase() : null;
    }
}

The two methods perform the same thing, just with flipped logic.
However, for toLowerCaseB we get an error:

Error: [conditional.type.incompatible] incompatible types in conditional expression.
   found   : null (NullType)
   required: @Initialized @NonNull String
@Ao-senXiong
Copy link
Member

A small question: why is the type of conditional expression text == null ? null : text.toLowerCase() is @Initialized @PolyNull String at first?

Ao-senXiong added a commit to Ao-senXiong/checker-framework that referenced this issue Jul 30, 2023
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