codeconsole opened a new pull request, #3277: URL: https://github.com/apache/groovy/pull/3277
Fixes [GROOVY-12742](https://issues.apache.org/jira/browse/GROOVY-12742). A class-level `@Invariant` on a class that implements a trait made every method the trait contributes return `null` (a primitive return failed with a `GroovyCastException`), and trait property accessors with it. `ClassInvariantGenerator.addInvariantAssertionStatement` wove the invariant call before each `return` only when the method body was a block; the forwarders and property accessors that `TraitComposer` generates have a bare expression or return statement as body, so the generator fell back to appending the void invariant call after it and the implicit return value was lost. The same fallback left a `@Synchronized` body unwrapped, so an explicit `return` inside it skipped the invariant. The generator now normalises the body to a block first, with the `ensureBlockBody` step the postcondition path has used since GROOVY-12084, so the implicit return becomes explicit and the invariant is checked before each return. The fallback remains only for a method without a body. Tests: seven new tests in `SimpleClassInvariantTests` (forwarders returning a primitive and an object, a void forwarder, a forwarder that violates the invariant, the class's own method beside forwarders, trait property accessors, and a `@Synchronized` method with an explicit return). Four of them fail on master with the null returns; the `groovy-contracts` module passes with the fix (403 tests). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
