Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
3.0.18, 4.0.13
-
None
-
None
-
Java : corretto-11.0.19
Ubuntu 22.04
Description
The following code fails to compile:
@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) }
With the error:
> 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 -> ^
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.
Attachments
Issue Links
- is related to
-
GROOVY-11089 STC: closure param type inference for array and list
- Closed
-
GROOVY-11124 iterating Tuple2s loses type parameters
- Closed
-
GROOVY-11125 withIndex().collect loses type parameters
- Closed
-
GROOVY-11090 STC: closure param type inference for tuple
- Closed