You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Mauro Molinari (JIRA)" <ji...@apache.org> on 2018/11/09 11:58:00 UTC

[jira] [Created] (GROOVY-8873) Fails at runtime with @CompileStatic and two nested with

Mauro Molinari created GROOVY-8873:
--------------------------------------

             Summary: Fails at runtime with @CompileStatic and two nested with
                 Key: GROOVY-8873
                 URL: https://issues.apache.org/jira/browse/GROOVY-8873
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation
    Affects Versions: 2.5.3, 2.4.15
            Reporter: Mauro Molinari


Consider this class:
{code:java}
package testgroovy

import groovy.transform.CompileStatic

@CompileStatic
class Foobar {
    
    static class Foo {
        String aaa = 'aaa'
        String bbb = 'bbb'
    }
    
    static class Bar {
        String ccc = 'ccc'
    }
    
    Foo foo = new Foo()
    Bar bar = new Bar()
    
    void foobar() {
        foo.with {
            bar.with {
                println aaa
                println bbb
                println ccc
            }
        }
    }

    static void main(String[] args) {
        new Foobar().foobar()
    }    
}{code}
It fails at runtime with:
{noformat}
Exception in thread "main" java.lang.ClassCastException: testgroovy.Foobar$Bar cannot be cast to groovy.lang.Closure
    at testgroovy.Foobar$_foobar_closure1$_closure2.doCall(Foobar.groovy:23)
    at testgroovy.Foobar$_foobar_closure1$_closure2.call(Foobar.groovy)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316)
    at testgroovy.Foobar$_foobar_closure1.doCall(Foobar.groovy:22)
    at testgroovy.Foobar$_foobar_closure1.call(Foobar.groovy)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316)
    at testgroovy.Foobar.foobar(Foobar.groovy:21)
    at testgroovy.Foobar.main(Foobar.groovy:31){noformat}
It works fine if you remove {{@CompileStatic}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)