[
https://issues.apache.org/jira/browse/GROOVY-11086?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17731484#comment-17731484
]
Thodoris Sotiropoulos commented on GROOVY-11086:
------------------------------------------------
If I am not mistaken, Java examines the type arguments, and not the return
target. The list overload is not applicable under the given type arguments. So
maybe Java does not put list overload into the set of applicable methods?
> Wrong method is chosen when having overloaded methods with bounded type
> parameters
> ----------------------------------------------------------------------------------
>
> Key: GROOVY-11086
> URL: https://issues.apache.org/jira/browse/GROOVY-11086
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Minor
> Labels: bounded-polymorphism, overloading
>
> I have the following program
> {code}
> import java.util.*;
> class Foo<T> {}
> class Bar<T> {}
> class Main {
> static final void test() {
> LinkedList<Number> x = null;
> Foo<Iterable<Number>> y = Main.<Number, Iterable<Number>>m(x);
> }
> static <X, T extends Iterable<X>> Foo<T> m(Iterable<X> x) {return null;}
> static <X, T extends List<X>> Bar<T> m(List<X> x) { return null; }
> }
> {code}
> h3. Actual behaviour
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> Main.groovy: 9: [Static type checking] - Cannot assign value of type Bar<T
> extends java.util.List<X>> to variable of type
> Foo<java.lang.Iterable<java.lang.Number>>
> @ line 9, column 31.
> Foo<Iterable<Number>> y = Main.<Number, Iterable<Number>>m(x);
> ^
> 1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> In particular, the chosen method is wrong. It's not even applicable as the
> provided type argument (at the call-site) does not respect the upper bound of
> the chosen method.
> h3. Notes
> Test case adapted from the following code that uses the assertj-core lib:
> {code}
> import java.util.*;
> import org.assertj.core.api.*;
> class Foo<T> {}
> class Bar<T> {}
> class Main {
> static final void test() {
> LinkedList<Number> x = null;
> FactoryBasedNavigableIterableAssert<?, Iterable<Number>, Number,
> ObjectAssert<Number>> res = Java6Assertions.assertThat(x, (y) -> x);
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)