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

Incorrect overload resolution ends in type error. #2941

Open
rluble opened this issue Sep 10, 2024 · 2 comments
Open

Incorrect overload resolution ends in type error. #2941

rluble opened this issue Sep 10, 2024 · 2 comments
Labels
bug Something isn't working regression Something was broken by a previous change

Comments

@rluble
Copy link

rluble commented Sep 10, 2024

The following code:

import static java.util.stream.Collectors.collectingAndThen;

import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Stream;

public abstract class BiStream<K, V> {
  public static <E, K, V> Collector<E, ?, BiStream<K, V>> toBiStream(
      Function<? super E, ? extends K> toKey, Function<? super E, ? extends V> toValue) {
    return collectingAndThen(toStream(), stream -> from(stream));
  }

  private static <T> Collector<T, ?, Stream<T>> toStream() {
    return null;
  }

  public static <T, K, V> BiStream<K, V> from(Iterable<T> elements) {
    return null;
  }

  public static <T, K, V> BiStream<K, V> from(Stream<T> stream) {
    return null;
  }
}

Fails to compile in ecj-4.32 with the following error:

1. ERROR in /Users/rluble/Downloads/BiStream.java (at line 10)
	return collectingAndThen(toStream(), stream -> from(stream));
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type mismatch: cannot convert from Collector<Object,Object,Object> to Collector<E,?,BiStream<K,V>>

This is the result of selecting the wrong overload and incorrectly depending on declaration order.

If the overloads are declared in a different order as in:

import static java.util.stream.Collectors.collectingAndThen;

import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Stream;

public abstract class BiStream<K, V> {
  public static <E, K, V> Collector<E, ?, BiStream<K, V>> toBiStream(
      Function<? super E, ? extends K> toKey, Function<? super E, ? extends V> toValue) {
    return collectingAndThen(toStream(), stream -> from(stream));
  }

  private static <T> Collector<T, ?, Stream<T>> toStream() {
    return null;
  }

  public static <T, K, V> BiStream<K, V> from(Stream<T> stream) {
    return null;
  }

  public static <T, K, V> BiStream<K, V> from(Iterable<T> elements) {
    return null;
  }
}

the code compiles.

@stephan-herrmann
Copy link
Contributor

ECJ 3.35 and earlier (Eclipse 4.29) successfully compile the original example.

I'll check what commit caused this change.

@jukzi jukzi added bug Something isn't working regression Something was broken by a previous change labels Sep 11, 2024
@rluble
Copy link
Author

rluble commented Sep 11, 2024

ECJ 3.35 and earlier (Eclipse 4.29) successfully compile the original example.

I just downloaded ecj-4.29 and the error is present there as well. ecj-4.28 compiles it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Something was broken by a previous change
Projects
None yet
Development

No branches or pull requests

3 participants