[groovy-user] Possible Bug in CompileStatic?

1 view
Skip to first unread message

Carlos Cortinhas

unread,
Sep 7, 2012, 11:06:54 AM9/7/12
to us...@groovy.codehaus.org
Hello guys,

I was working with Closures and testing the CompileStatic feature, and I noticed a possible bug in the following code:

@groovy.transform.CompileStatic
class Foo{
    def run(){
        Closure a ={
            int i ->
            println "First closure "+ i
        }
        Closure b ={
            String s ->
            println "Second closure "+ s
        }
        a=b
        a("Testing!")
    }
}
Foo f = new Foo()
f.run()

With CS applied the code will fail to compile with the following error:

[Static type checking] - Closure argument types: [int] do not match with parameter types: [java.lang.String]
at line: 13, column: 11

The compiler is expecting an integer but since the variable 'a' is re-assigned to a new piece of code that takes a String as a parameter should this error be thrown?

But if I turn off the CS the code will work just fine. Is this supposed to be like this?

Thanks,
Carlos

Cédric Champeau

unread,
Sep 7, 2012, 11:13:08 AM9/7/12
to us...@groovy.codehaus.org
Le 07/09/2012 17:06, Carlos Cortinhas a �crit :
> @groovy.transform.CompileStatic
> class Foo{
> def run(){
> Closure a ={
> int i ->
> println "First closure "+ i
> }
> Closure b ={
> String s ->
> println "Second closure "+ s
> }
> a=b
> a("Testing!")
> }
> }
> Foo f = new Foo()
> f.run()
This is a bug, more precisely the combination of flow typing and closure
argument types checking. Can you file a jira issue?

Thanks!

--
C�dric Champeau
SpringSource - A Division Of VMware
http://www.springsource.com/
http://twitter.com/CedricChampeau


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Carlos Cortinhas

unread,
Sep 7, 2012, 3:55:40 PM9/7/12
to us...@groovy.codehaus.org
Em 07-09-2012 16:13, C�dric Champeau escreveu:
> Le 07/09/2012 17:06, Carlos Cortinhas a �crit :
>> @groovy.transform.CompileStatic
>> class Foo{
>> def run(){
>> Closure a ={
>> int i ->
>> println "First closure "+ i
>> }
>> Closure b ={
>> String s ->
>> println "Second closure "+ s
>> }
>> a=b
>> a("Testing!")
>> }
>> }
>> Foo f = new Foo()
>> f.run()
> This is a bug, more precisely the combination of flow typing and
> closure argument types checking. Can you file a jira issue?
>
> Thanks!
>
Done. It's Groovy-5693
Thanks,
Carlos
Reply all
Reply to author
Forward
0 new messages