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

Ben Sherman updated GROOVY-11864:
---------------------------------
    Description: 
 

Full context is in this GitHub PR: 
[nextflow-io/nextflow#6220|https://github.com/nextflow-io/nextflow/pull/6220/changes#r2666555282]

I have created a minimal example below. The instanceof pattern {{source 
instanceof DataflowWriteChannel}} seems to apply the type 
{{DataflowWriteChannel}} to {{source}} for the remainder of the method, causing 
a type checking error downstream.

The outer if statement and the throw statement seem to be relevant factors, but 
I'm not sure of the exact cause.

The gpars classes come from {{org.codehaus.gpars:gpars:1.2.1}} , but I assume 
the same error can be reproduced with any similar types

Minimal example:
{code:java}
import groovy.transform.CompileStatic
import groovyx.gpars.dataflow.DataflowReadChannel
import groovyx.gpars.dataflow.DataflowWriteChannel

@CompileStatic
class Test {

    private DataflowReadChannel source

    boolean isEnabled() {
    }

    DataflowWriteChannel apply() {
        if( !isEnabled() ) {
            if( source instanceof DataflowWriteChannel )
                return source
            throw new IllegalArgumentException("")
        }

        // ERROR: Cannot find matching static method 
Test#createBy(groovyx.gpars.dataflow.DataflowWriteChannel)
        createBy(source)
    }

    static DataflowWriteChannel createBy(DataflowReadChannel channel) {
    }
}
{code}
 

 

  was:
 

Full context is in this GitHub PR: 
[nextflow-io/nextflow#6220|https://github.com/nextflow-io/nextflow/pull/6220/changes#r2666555282]

I have created a minimal example below. The instanceof pattern {{source 
instanceof DataflowWriteChannel}} seems to apply the type 
{{DataflowWriteChannel}} to {{source}} for the remainder of the method, causing 
a type checking error downstream.

The outer if statement and the throw statement seem to be relevant factors, but 
I'm not sure of the exact cause.

The gpars classes come from {{org.codehaus.gpars:gpars:1.2.1}} , but I assume 
the same error can be reproduced with any similar types

Minimal example:
{code:java}
import groovy.transform.CompileStatic
import groovyx.gpars.dataflow.DataflowReadChannel
import groovyx.gpars.dataflow.DataflowWriteChannel

@CompileStatic
class Test {

    private DataflowReadChannel source

    boolean isEnabled() {
    }

    DataflowWriteChannel apply() {
        if( !isEnabled() ) {
            if( source instanceof DataflowWriteChannel )
                return source
            throw new IllegalArgumentException("")
        }

        // ERROR: Cannot find matching static method 
nextflow.extension.CH#createBy(groovyx.gpars.dataflow.DataflowWriteChannel)
        createBy(source)
    }

    static DataflowWriteChannel createBy(DataflowReadChannel channel) {
    }
}
{code}
 

 


> instanceof pattern is incorrectly applied to downstream code in type checker
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-11864
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11864
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 5.0.4
>            Reporter: Ben Sherman
>            Priority: Major
>
>  
> Full context is in this GitHub PR: 
> [nextflow-io/nextflow#6220|https://github.com/nextflow-io/nextflow/pull/6220/changes#r2666555282]
> I have created a minimal example below. The instanceof pattern {{source 
> instanceof DataflowWriteChannel}} seems to apply the type 
> {{DataflowWriteChannel}} to {{source}} for the remainder of the method, 
> causing a type checking error downstream.
> The outer if statement and the throw statement seem to be relevant factors, 
> but I'm not sure of the exact cause.
> The gpars classes come from {{org.codehaus.gpars:gpars:1.2.1}} , but I assume 
> the same error can be reproduced with any similar types
> Minimal example:
> {code:java}
> import groovy.transform.CompileStatic
> import groovyx.gpars.dataflow.DataflowReadChannel
> import groovyx.gpars.dataflow.DataflowWriteChannel
> @CompileStatic
> class Test {
>     private DataflowReadChannel source
>     boolean isEnabled() {
>     }
>     DataflowWriteChannel apply() {
>         if( !isEnabled() ) {
>             if( source instanceof DataflowWriteChannel )
>                 return source
>             throw new IllegalArgumentException("")
>         }
>         // ERROR: Cannot find matching static method 
> Test#createBy(groovyx.gpars.dataflow.DataflowWriteChannel)
>         createBy(source)
>     }
>     static DataflowWriteChannel createBy(DataflowReadChannel channel) {
>     }
> }
> {code}
>  
>  



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

Reply via email to