Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.8, 2.1.3
-
None
Description
I'm seeing a compilation error with this code:
def zipFile = new ZipFile(self) for (ZipArchiveEntry entry in zipFile.entries) { ... }
The error:
lazybones/src/main/groovy/uk/co/cacoethes/util/ArchiveMethods.groovy: 36: [Static type checking] - Cannot loop with element of type org.apache.commons.compress.archivers.zip.ZipArchiveEntry with collection of type java.util.Enumeration <org.apache.commons.compress.archivers.zip.ZipArchiveEntry> @ line 36, column 9. for (ZipArchiveEntry entry in zipFile.entries) { ^ 1 error
It seems that the static compilation doesn't like generic {{Enumeration}}s because this compiles file if I modify it slightly to look like:
def zipFile = new ZipFile(self) for (ZipArchiveEntry entry in (zipFile.entries as List<ZipArchiveEntry>)) { ... }
I have attached a sample Gradle project to demonstrate the problem. Simply unpack it into a fresh directory and run ./gradlew compileGroovy.
Attachments
Attachments
Issue Links
- is duplicated by
-
GROOVY-6240 static type checker cannot infer type of for loop variable from map
- Closed