You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/09/04 13:29:00 UTC
[jira] [Resolved] (GROOVY-7179) Type inference fails on the return value of inject()
[ https://issues.apache.org/jira/browse/GROOVY-7179?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-7179.
---------------------------------
Resolution: Fixed
> Type inference fails on the return value of inject()
> ----------------------------------------------------
>
> Key: GROOVY-7179
> URL: https://issues.apache.org/jira/browse/GROOVY-7179
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 2.3.7, 2.4.1
> Reporter: Yu Kobayashi
> Priority: Major
>
> Type inference fails on the return value of inject().
> {code}
> @groovy.transform.CompileStatic
> List<Integer> test() {
> (2..3).inject([1], { list, i -> list << i })
> }
> println test()
> {code}
> Error message:
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> C:\Users\Yu\Desktop\test.groovy: 3: [Static type checking] - Cannot return value of type java.lang.Object on method returning type java.util.List <Integer> @ line 3, column 5.
> (2..3).inject([1], { list, i -> list + i })
> ^
> {code}
> By the way, IntelliJ IDEA 14 fails on inferencing closure argument types, and success on the return type for this code.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)