[ 
https://issues.apache.org/jira/browse/GROOVY-12742?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140824#comment-18140824
 ] 

ASF GitHub Bot commented on GROOVY-12742:
-----------------------------------------

codecov-commenter commented on PR #3277:
URL: https://github.com/apache/groovy/pull/3277#issuecomment-6725354035

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3277?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 74.4118%. Comparing base 
([`df1fe66`](https://app.codecov.io/gh/apache/groovy/commit/df1fe66ed134c0ec484117a526e2e8a420307e0b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`ed15df3`](https://app.codecov.io/gh/apache/groovy/commit/ed15df3625aa7ab662b11418534811b395b68bfe?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3277/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/3277?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3277        +/-   ##
   ==================================================
   - Coverage     74.4140%   74.4118%   -0.0022%     
   - Complexity      44379      44396        +17     
   ==================================================
     Files            1699       1699                
     Lines          151067     151148        +81     
     Branches        28790      28798         +8     
   ==================================================
   + Hits           112415     112472        +57     
   - Misses          28380      28393        +13     
   - Partials        10272      10283        +11     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3277?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[.../contracts/generation/ClassInvariantGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/3277?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fgeneration%2FClassInvariantGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9nZW5lcmF0aW9uL0NsYXNzSW52YXJpYW50R2VuZXJhdG9yLmphdmE=)
 | `90.0000% <100.0000%> (-0.6250%)` | :arrow_down: |
   
   ... and [20 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3277/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test 
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, 
report on failures, and find test suite problems.
   - :package: [JS Bundle 
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save 
yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>




> groovy-contracts: a class invariant makes the trait forwarders and trait 
> property accessors of the class return null
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12742
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12742
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-contracts
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> h3. Problem
> A class-level {{@Invariant}} on a class that implements a trait makes every 
> method the trait contributes return {{null}}; a primitive return fails with a 
> cast exception:
> {code:groovy}
> import groovy.contracts.*
> trait Named {
>     String name = 'x'
>     String greet() { "hi $name" }
>     int one() { 1 }
> }
> @Invariant({ count >= 0 })
> class Counter implements Named {
>     int count
> }
> def c = new Counter()
> assert c.greet() == 'hi x'   // greet() returns null
> c.one()                       // GroovyCastException: Cannot cast 'null' to 
> class 'int'
> {code}
> Trait properties are affected too ({{getSize()}} of a trait property {{int 
> size}} fails the same way). The interface equivalent, where the class writes 
> the method bodies itself, is fine. Reproduced on Groovy 6.0.0 and on master 
> (df1fe66ed1).
> h3. Cause
> {{ClassInvariantGenerator.addInvariantAssertionStatement}} weaves the 
> invariant call before each {{return}} only when the method body is a block. 
> The forwarders and property accessors that {{TraitComposer}} generates in the 
> implementing class have a bare expression or return statement as body, so the 
> generator fell back to appending the (void) invariant call after it, and the 
> forwarder's implicit return value was lost. The same fallback left a 
> {{@Synchronized}} body unwrapped, so an explicit {{return}} inside it skipped 
> the invariant.
> h3. Fix
> Normalise the body to a block first (the {{ensureBlockBody}} step the 
> postcondition path already performs since GROOVY-12084), so the implicit 
> return is made explicit and the invariant is checked before each return. 
> Trait forwarders and property accessors keep their values and are checked; 
> the {{@Synchronized}} explicit-return case is checked as well. Pull request 
> to follow.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to