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/07/24 22:50:00 UTC

[jira] [Comment Edited] (GROOVY-11135) Unable to compile: Expected type java.lang.Object for closure parameter

    [ https://issues.apache.org/jira/browse/GROOVY-11135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17746670#comment-17746670 ] 

Eric Milles edited comment on GROOVY-11135 at 7/24/23 10:49 PM:
----------------------------------------------------------------

GROOVY-11089 caused this fail.  GROOVY-11090 has the fix.  I'm not 100% how the runtime will behave without GROOVY-11092 and some other closure/lambda param count and type checks.

This idiom is cross-compatible:
{code:groovy}
@groovy.transform.CompileStatic
Map<Integer, String> files = new File("/").listFiles().toList().withIndex().collectEntries {
    def (File file, int index) = it
    return [(index) : file.name]
}
{code}



was (Author: emilles):
GROOVY-11089 caused this fail.  GROOVY-11090 has the fix.  I'm not 100% how the runtime will behave without GROOVY-10092 and some other closure/lambda param count and type checks.

This idiom is cross-compatible:
{code:groovy}
@groovy.transform.CompileStatic
Map<Integer, String> files = new File("/").listFiles().toList().withIndex().collectEntries {
    def (File file, int index) = it
    return [(index) : file.name]
}
{code}


> Unable to compile: Expected type java.lang.Object for closure parameter
> -----------------------------------------------------------------------
>
>                 Key: GROOVY-11135
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11135
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation
>    Affects Versions: 3.0.18, 4.0.13
>         Environment: Java : corretto-11.0.19
> Ubuntu 22.04
>            Reporter: A. Lepe
>            Assignee: Eric Milles
>            Priority: Major
>
> The following code fails to compile:
> {code:java}
> @groovy.transform.CompileStatic
> Map<Integer, String> files = new File("/").listFiles().toList().withIndex().collectEntries {
>     File file, int index ->
>         [(index) : file.name]
> }   
> files.each {
>     int i, String name ->
>         println String.format("%d : %s", i, name)
> }
> {code}
> With the error:
> {noformat}
> > Task :compileGroovy
> startup failed:
> groovy-bugs/app/src/main/groovy/com/intellisrc/groovy/App.groovy: 9: [Static type checking] - Expected type java.lang.Object for closure parameter: file
>  @ line 9, column 4.
>                File file, int index ->
>       ^
> {noformat}
> I have prepared a small project for testing:
> [https://gitlab.com/intellisrc/groovy-bugs/-/tree/with-index?ref_type=heads]
> Versions 3.0.17 , 4.0.12 and below seems to work as expected.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)