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

Type arg inference false positive because of qualifiers #6716

Open
smillst opened this issue Jul 17, 2024 · 0 comments
Open

Type arg inference false positive because of qualifiers #6716

smillst opened this issue Jul 17, 2024 · 0 comments
Assignees

Comments

@smillst
Copy link
Member

smillst commented Jul 17, 2024

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Stream;
import org.checkerframework.checker.interning.qual.Interned;

public class InterningError {

  void method(Stream<Integer> integerStream) {
    LinkedHashMap<Integer, Integer> c = integerStream.collect(
        toMap(Function.identity(), v -> 1, InterningError::sum));
  }

  public static <T, K, U, M extends Map<K, U>> Collector<T, ?, M> toMap(
      Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper,
      BinaryOperator<U> mergeFunction) {
    throw new RuntimeException();
  }

  static @Interned Integer sum(Integer a, Integer b) {
    return a + b;
  }

}

Produces the following false positive with the Interning Checker:

InterningError.java:12: error: [type.arguments.not.inferred] Could not infer type arguments for Stream.collect
    LinkedHashMap<Integer, Integer> c = integerStream.collect(
                                                             ^
  unsatisfiable constraint: LinkedHashMap<Integer, Integer> <: Map<Integer, @Interned Integer>
1 error

Inference should be able to correctly infer the type arguments in this case. I think there's a bug in the qualifier constraints some where.

@smillst smillst self-assigned this Jul 17, 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

1 participant