[ 
https://issues.apache.org/jira/browse/GROOVY-11863?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ben Sherman updated GROOVY-11863:
---------------------------------
    Description: 
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:
{code:java}
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 ) {
                }
            }
        }
    }
}{code}

  was:
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:

 
{code:java}
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 ) {
                }
            }
        }
    }
}{code}


> 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
>            Priority: Minor
>
> 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:
> {code:java}
> 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 ) {
>                 }
>             }
>         }
>     }
> }{code}



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

Reply via email to