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

False positive when assigning result of function with type parameters to var #6741

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

Comments

@MichalStehlikCz
Copy link
Contributor

Might be related to issue #6675

public class Test {

  public static <T> List<T> getInParameter(T value, Class<T> type) {
    return new ArrayList<>(5);
  }

  List<?> getInParameter() {
    var value = 5;
    var type = Integer.class;
    var result = getInParameter(value, type);
    return result;
  }
}

results in

C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java
java: [type.argument] incompatible type argument for type parameter E of List.
  found   : @UnknownInitialization @NonNull Integer
  required: @Initialized @Nullable Object
C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:16:32
java: [assignment] incompatible types in assignment.
  found   : @Initialized @NonNull List<@Initialized @NonNull Integer>
  required: @UnknownInitialization @Nullable List<@UnknownInitialization @NonNull Integer>

It should compile without problem.

It compiled in 3.42.0, fails in 3.46.0

If explicit type is specified for target
List<Integer> result = getInParameter(value, type);
it compiles without problem

@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