andresteingress / gcontracts

GContracts: Programming by Contract for Groovy
http://gcontracts.org
114 stars 11 forks source link

Nested closures #46

Open barneyb opened 10 years ago

barneyb commented 10 years ago

Given this code (which I believe should be valid):

@Ensures({ result.every { t -> t.target == target } })
Collection<Mapping> getMappings(Entity target) {
    // buncha code...
}

The compiler gives this error:

Error:(33, 29) Groovyc: [GContracts] Postconditions only allow 'old' and 'result' closure parameters.

I've never done anything with the Groovy AST stuff, but from a quick look at the code, I suspect that the ClosureExpressionValidator instance is recursing to the inner closure when it visits the AST of the closure passed to @Ensures, instead of just doing the top-level one. The inner closure is not a valid top-level closure, but I don't think it should have to be.