Variables not avaliable in inner scope in groovy (IDEA10)

I've tried this in Intellij IDEA 10.0-B99.18 and in 9.0.4-B95.627.
When debugging in groovy, a variable defined in the scope of a method or action, cannot be evaluated or put in "watches" inside a closure's scope,
but yet can be found in the "Variables" tab into the "this" variable.
For example:

class Lixo extends GroovyTestCase {
    void testLixo(){
        def mapa = [:]
        (1..2).each {
            mapa["a"] = "a" //Debug point
        }
    }
}



When debuggin at the marked line, "mapa" cannot be evaluated, nor added to the "watches" tab. But, in "Variables" tab, the "this" object contains "mapa".
Even if I evaluate the whole iteration :
"(1..2).each {
    mapa["a"] = "a"
}" , it outputs an error of "Cannot find local variable "mapa".
3 comments
Comment actions Permalink

Anybody please?

0
Comment actions Permalink

Hi.

Created http://youtrack.jetbrains.net/issue/IDEA-63465

I presume that current behavior is not necessary an error, since the breakpoint is set in the scope of a closure, which turns into inner class after compiling. So, 'mapa' is the local variable for a method of Lixo class, but a field for an object of generated inner class. But resolving of 'mapa' in Watches could be provided as a usability improvement.

Regards,
Alexander.

0
Comment actions Permalink

I now understand why the behavior is "expected", put the inner and restrictive scope of the closure. Thank you very much for clarifying it for me.

Anyway, it is of much value for me to be able to evaluate an expression inside such scopes that uses or references outsiders. Adding support to the Watches tab
seems more than half way to add it to Evaluate context.

Will stay tuned to it, and hope to see this improvement!

Frederico Galvão.

0

Please sign in to leave a comment.