[
https://issues.apache.org/jira/browse/GROOVY-11086?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Thodoris Sotiropoulos updated GROOVY-11086:
-------------------------------------------
Description:
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}
was:
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<? extends X>> Foo<T> m(Iterable<? extends X> x)
{return null;}
static <X, T extends List<? extends X>> Bar<T> m(List<? extends X> x) {
return null; }
}
{code}
h3. Actual behaviour
{code}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 10: [Static type checking] - Cannot assign value of type Bar<T
extends java.util.List<? extends X>> to variable of type
Foo<java.lang.Iterable<java.lang.Number>>
@ line 10, 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}
> 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
> 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)