ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

@Field fields declared in normal classes don't get initialized properly #309

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
While fields marked with @Field get initialized properly when used inside 
closures, when used in regular classes, their initialization does not happen 
properly (it should be correctly moved to the constructors).

The snippet below demonstrates the difference between the 2 cases:
--------------------------------------------------
@Typed package test

def foo() {
    @Field mf = 5
    mf++
    println mf     
}

println "@Field usage inside closure"
(1..2).each{
    @Field cf = 5
    cf++
    println cf     
}

println "@Field usage inside method"
(1..2).each{
    foo()
}
--------------------------------------------------

In both the cases, the output is expected to be 6, 7 - but for the method case, 
it incorrectly comes as 1, 2 because the field's initial value of 5 is lost.

Original issue reported on code.google.com by roshanda...@gmail.com on 16 Oct 2010 at 4:28

GoogleCodeExporter commented 8 years ago

Original comment by alex.tka...@gmail.com on 17 Oct 2010 at 5:53