Thodoris Sotiropoulos created GROOVY-11021:
----------------------------------------------
Summary: Resolving wrong overloaded method when having variable
arguments
Key: GROOVY-11021
URL: https://issues.apache.org/jira/browse/GROOVY-11021
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Reporter: Thodoris Sotiropoulos
This might be related to GROOVY-11002.
I have the following program
{code}
import java.util.Comparator;
class Bar<T> {
static <T> Bar<T> concat(Bar<? extends T>... x) { return null; }
static <T> Bar<T> concat(Bar<? extends Bar<? extends T>> x) { return null; }
void toSortedSet(Comparator<? super T> x) {}
}
class Main {
static final void test() {
Bar<Foo<Number>> x = null;
Comparator<Foo<Number>> y = null;
Bar.concat(x).toSortedSet(y);
}
}
{code}
h3. Actual behavior
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
groovy35.groovy: 15: [Static type checking] - Cannot call <T> Bar#concat(Bar<?
extends Bar<? extends T>>) with arguments [Bar<Foo<java.lang.Number>>]
@ line 15, column 15.
Bar.concat(x).toSortedSet(y);
^
groovy35.groovy: 15: [Static type checking] - Cannot find matching method
java.lang.Object#toSortedSet(java.util.Comparator<Foo<java.lang.Number>>).
Please check if the declared type is correct and if the method exists.
@ line 15, column 5.
Bar.concat(x).toSortedSet(y);
^
2 errors
{code}
h3. Expected behavior
Compile successfully
h3. Notes
Tested against master (commit: efe514a5e28828309e7decbfaf923b5c7f42b05d)
To reproduce the bug, two overloaded methods are needed; one of them should
contain variable arguments.
Test cased adapted from the following program that uses the Guava library
{code}
import com.google.common.collect.*;
import java.util.Comparator;
class Foo<K> {}
class Main {
static final void test() {
Iterable<? extends Foo<Number>> x = null;
Comparator<? super Foo<Number>> y = null;
FluentIterable.concat(x).toSortedSet(y);
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)