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

Inference is not able to use return type in @Nullable type inference #6748

Open
MichalStehlikCz opened this issue Aug 8, 2024 · 0 comments
Assignees

Comments

@MichalStehlikCz
Copy link
Contributor

MichalStehlikCz commented Aug 8, 2024

In this example

@SuppressWarnings("nullity")
class Test {

  abstract static class Typed<T> {

    abstract T get();
  }

  <T> Optional<T> method1(Typed<? extends @Nullable T> arg) {
    return Optional.ofNullable(arg.get());
  }

  <T> Optional<T> method2(Typed<? extends @Nullable T> arg) {
    return method1(arg);
  }
}

compilation fails with error in method2

C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:23:19
java: [return] incompatible types in return.
  type of expression: @Initialized @NonNull Optional<T extends @Initialized @NonNull Object>
  method return type: @Initialized @NonNull Optional<T extends @Initialized @Nullable Object>

I believe it should compile without warning, as if it used T as type argument in call to method1, all should be fine

@smillst smillst self-assigned this Aug 8, 2024
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

No branches or pull requests

2 participants