[
https://issues.apache.org/jira/browse/GROOVY-9762?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Marcin Zajaczkowski updated GROOVY-9762:
----------------------------------------
Description:
I've encountered a problem with type checking if a method reference is used.
In following (stripped down from the original production case) code in the line
with the error variable the following error is reported:
{code:java}
> Task :compileTestGroovy
startup failed:
/home/foobar.../MethodReferenceProblemWithType.groovy: 15: [Static type
checking] - Cannot assign value of type java.lang.Object to variable of type
java.util.List <Integer>
@ line 15, column 31.
List<Integer> error = opt.map(this::just).get() {code}
{code:java}
@CompileStatic
class MethodReferenceProblemWithType {
static void reproduce() {
Optional<Integer> opt = Optional.ofNullable(Integer.valueOf(1))
List<Integer> ok = opt.map(o -> just(o)).get() //ok
List<Integer> error = opt.map(this::just).get() //problem
}
private static <T> List<T> just(T data) {
return new ArrayList<T>();
}
} {code}
If `@CompileStatic` is removed, I still see a type incompatibility warning in
Idea. Switching to lambda is a workaround, therefore it's just a minor glitch.
Tested with Groovy 3.0.5.
was:
I've encountered a problem with type checking if a method reference is used.
In following (stripped down from the original production case) code in the line
with the error variable the following error is reported:
{code:java}
> Task :compileTestGroovy
startup failed:
/home/foobar.../MethodReferenceProblemWithType.groovy: 15: [Static type
checking] - Cannot assign value of type java.lang.Object to variable of type
java.util.List <Integer>
@ line 15, column 31.
List<Integer> error = opt.map(this::just).get() {code}
{code:java}
@CompileStatic
class MethodReferenceProblemWithType {
static void reproduce() {
Optional<Integer> opt = Optional.ofNullable(Integer.valueOf(1))
List<Integer> ok = opt.map(o -> just(o)).get() //ok
List<Integer> error = opt.map(this::just).get() //problem
}
private static <T> List<T> just(T data) {
return new ArrayList<T>();
}
} {code}
If `@CompileStatic` is removed, I still see a type incompatibility warning in
Idea. Switching to lambda is an workaround. Tested with Groovy 3.0.5.
> Wrong type resolved if method reference used with typed method
> --------------------------------------------------------------
>
> Key: GROOVY-9762
> URL: https://issues.apache.org/jira/browse/GROOVY-9762
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.5
> Reporter: Marcin Zajaczkowski
> Priority: Minor
>
> I've encountered a problem with type checking if a method reference is used.
> In following (stripped down from the original production case) code in the
> line with the error variable the following error is reported:
> {code:java}
> > Task :compileTestGroovy
> startup failed:
> /home/foobar.../MethodReferenceProblemWithType.groovy: 15: [Static type
> checking] - Cannot assign value of type java.lang.Object to variable of type
> java.util.List <Integer>
> @ line 15, column 31.
> List<Integer> error = opt.map(this::just).get() {code}
> {code:java}
> @CompileStatic
> class MethodReferenceProblemWithType {
> static void reproduce() {
> Optional<Integer> opt = Optional.ofNullable(Integer.valueOf(1))
> List<Integer> ok = opt.map(o -> just(o)).get() //ok
> List<Integer> error = opt.map(this::just).get() //problem
> }
> private static <T> List<T> just(T data) {
> return new ArrayList<T>();
> }
> } {code}
> If `@CompileStatic` is removed, I still see a type incompatibility warning in
> Idea. Switching to lambda is a workaround, therefore it's just a minor
> glitch. Tested with Groovy 3.0.5.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)