Ben Sherman created GROOVY-11863:
------------------------------------
Summary: False type checking error in inner class with delegate
field
Key: GROOVY-11863
URL: https://issues.apache.org/jira/browse/GROOVY-11863
Project: Groovy
Issue Type: Bug
Components: Static Type Checker
Affects Versions: 5.0.4
Reporter: Ben Sherman
Full context is in this GitHub PR:
[nextflow-io/nextflow#6220|https://github.com/nextflow-io/nextflow/pull/6220/changes#r2666549692]
I encountered a false type checking error while trying to upgrade Nextflow from
Groovy 4 to 5. I have created a minimal example below. The comparison "c++ <
MAX_LINES" is reported as a type mismatch even though both are integer types.
The factors seem to be (1) an inner class, (2) a delegate field, and (3) a
while loop. But I'm not sure what the exact cause is.
In my case, the inner class is static, so I can work around the error by moving
the inner class outside.
Minimal example:
```groovy
import java.nio.file.Path
import groovy.transform.CompileStatic
@CompileStatic
class Test {
class Inner {
static private int MAX_LINES = 100
@Delegate
private Map<String,Object> delegate = [:]
private String fetch(Path path) {
int c=0
path.withReader { reader ->
// ERROR: Cannot call
java.lang.Integer#compareTo(java.lang.Integer) with arguments [java.lang.Object]
while( c++ < MAX_LINES ) {
}
}
}
}
}
```
--
This message was sent by Atlassian Jira
(v8.20.10#820010)