groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From César Izurieta (JIRA) <j...@apache.org>
Subject [jira] [Updated] (GROOVY-7512) Cannot call Trait method from Closure when using static compilation
Date Mon, 20 Jul 2015 14:58:05 GMT

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

César Izurieta updated GROOVY-7512:
-----------------------------------
    Description: 
When running:

{code:title=test.groovy|borderStyle=solid}
class X {
    Closure action = {}
}

trait T {

    void say(String text) {
        println text
    }

    @groovy.transform.CompileStatic
    X getX() {
        new X(action: {
            say "Hello!"
        })
    }

}

class A implements T {
}

new A().x.action()
{code}

The following exception is thrown:

{code}
Caught: java.lang.ClassCastException: java.lang.Class cannot be cast to T
java.lang.ClassCastException: java.lang.Class cannot be cast to T
	at T$Trait$Helper$_getX_closure1.doCall(test.groovy:14)
	at T$Trait$Helper$_getX_closure1.doCall(test.groovy)
	at test.run(test.groovy:23)
{code}

This is only happening on groovy 2.4.4. Removing the static compilation annotation or reverting
to groovy version 2.4.3 makes the code work. 

The commit that is causing this problem seems to be: 1bbed25aa3a08bc0cb7e14e49a1e7c2b82f21a26

  was:
When running:

{code:title=test.groovy|borderStyle=solid}
class X {
    Closure action = {}
}

trait T {

    void say(String text) {
        println text
    }

    @groovy.transform.CompileStatic
    X getX() {
        new X(action: {
            say "Hello!"
        })
    }

}

class A implements T {
}

new A().x.action()
{code}

The following exception is thrown:

{code}
Caught: java.lang.ClassCastException: java.lang.Class cannot be cast to T
java.lang.ClassCastException: java.lang.Class cannot be cast to T
	at T$Trait$Helper$_getX_closure1.doCall(Test2.groovy:14)
	at T$Trait$Helper$_getX_closure1.doCall(Test2.groovy)
	at Test2.run(Test2.groovy:23)
{code}

This is only happening on groovy 2.4.4. Removing the static compilation annotation or reverting
to groovy version 2.4.3 makes the code work. 

The commit that is causing this problem seems to be: 1bbed25aa3a08bc0cb7e14e49a1e7c2b82f21a26


> Cannot call Trait method from Closure when using static compilation
> -------------------------------------------------------------------
>
>                 Key: GROOVY-7512
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7512
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static compilation, Static Type Checker
>    Affects Versions: 2.4.4
>            Reporter: César Izurieta
>            Assignee: Cédric Champeau
>
> When running:
> {code:title=test.groovy|borderStyle=solid}
> class X {
>     Closure action = {}
> }
> trait T {
>     void say(String text) {
>         println text
>     }
>     @groovy.transform.CompileStatic
>     X getX() {
>         new X(action: {
>             say "Hello!"
>         })
>     }
> }
> class A implements T {
> }
> new A().x.action()
> {code}
> The following exception is thrown:
> {code}
> Caught: java.lang.ClassCastException: java.lang.Class cannot be cast to T
> java.lang.ClassCastException: java.lang.Class cannot be cast to T
> 	at T$Trait$Helper$_getX_closure1.doCall(test.groovy:14)
> 	at T$Trait$Helper$_getX_closure1.doCall(test.groovy)
> 	at test.run(test.groovy:23)
> {code}
> This is only happening on groovy 2.4.4. Removing the static compilation annotation or
reverting to groovy version 2.4.3 makes the code work. 
> The commit that is causing this problem seems to be: 1bbed25aa3a08bc0cb7e14e49a1e7c2b82f21a26



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message