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

Refinement lost for switch expressions with yields. #5967

Closed
smillst opened this issue May 30, 2023 · 0 comments · Fixed by #6192
Closed

Refinement lost for switch expressions with yields. #5967

smillst opened this issue May 30, 2023 · 0 comments · Fixed by #6192

Comments

@smillst
Copy link
Member

smillst commented May 30, 2023

The following code should type check without any errors.

import java.util.function.Supplier;
import org.checkerframework.checker.nullness.qual.NonNull;

public final class IssueXXX {
  enum TestEnum { FIRST, SECOND };

  public static void main(String[] args) {
    TestEnum testEnum = TestEnum.FIRST;
 Supplier<Integer> supplier = switch (testEnum) {
      case FIRST: yield () -> 1;
      case SECOND: yield() -> 2;
    };
   @NonNull Supplier<Integer> supplier1 = supplier;
  }
}
../testcases/src/Issue5930.java:13: error: [assignment] incompatible types in assignment.
   @NonNull Supplier<Integer> supplier1 = supplier;
                                          ^
  found   : @UnknownInitialization @Nullable Supplier<@Initialized @NonNull Integer>
  required: @UnknownInitialization @NonNull Supplier<@Initialized @NonNull Integer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant