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

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

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

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3371?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :x: Patch coverage is `85.89744%` with `11 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 75.2954%. Comparing base 
([`494d161`](https://app.codecov.io/gh/apache/groovy/commit/494d161bb13d832e65136174312ea6609867d869?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`6ee1060`](https://app.codecov.io/gh/apache/groovy/commit/6ee1060893abc30b426bf5f58ca7261d0c1d876b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3371?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[...ontracts/ast/visitor/AnnotationClosureVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2Fvisitor%2FAnnotationClosureVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvdmlzaXRvci9Bbm5vdGF0aW9uQ2xvc3VyZVZpc2l0b3IuamF2YQ==)
 | 72.9730% | [0 Missing and 10 partials :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   | 
[...vy/contracts/generation/PreconditionGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fgeneration%2FPreconditionGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9nZW5lcmF0aW9uL1ByZWNvbmRpdGlvbkdlbmVyYXRvci5qYXZh)
 | 0.0000% | [0 Missing and 1 partial :warning: 
](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3371/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/3371?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3371        +/-   ##
   ==================================================
   + Coverage     75.2860%   75.2954%   +0.0095%     
   - Complexity      49967      50000        +33     
   ==================================================
     Files            1775       1776         +1     
     Lines          163660     163731        +71     
     Branches        32301      32328        +27     
   ==================================================
   + Hits           123213     123282        +69     
     Misses          28947      28947                
   - Partials        11500      11502         +2     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3371?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[.../ClosureExpressionEvaluationASTTransformation.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2FClosureExpressionEvaluationASTTransformation.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvQ2xvc3VyZUV4cHJlc3Npb25FdmFsdWF0aW9uQVNUVHJhbnNmb3JtYXRpb24uamF2YQ==)
 | `93.9394% <100.0000%> (+0.2552%)` | :arrow_up: |
   | 
[...oovy/contracts/ast/visitor/ConfigurationSetup.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2Fvisitor%2FConfigurationSetup.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvdmlzaXRvci9Db25maWd1cmF0aW9uU2V0dXAuamF2YQ==)
 | `100.0000% <100.0000%> (ø)` | |
   | 
[...che/groovy/contracts/generation/BaseGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fgeneration%2FBaseGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9nZW5lcmF0aW9uL0Jhc2VHZW5lcmF0b3IuamF2YQ==)
 | `95.4546% <100.0000%> (+0.1420%)` | :arrow_up: |
   | 
[...y/contracts/generation/PostconditionGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fgeneration%2FPostconditionGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9nZW5lcmF0aW9uL1Bvc3Rjb25kaXRpb25HZW5lcmF0b3IuamF2YQ==)
 | `97.5000% <100.0000%> (+0.8898%)` | :arrow_up: |
   | 
[...rg/apache/groovy/contracts/util/OldProperties.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Futil%2FOldProperties.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy91dGlsL09sZFByb3BlcnRpZXMuamF2YQ==)
 | `100.0000% <100.0000%> (ø)` | |
   | 
[...vy/contracts/generation/PreconditionGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fgeneration%2FPreconditionGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9nZW5lcmF0aW9uL1ByZWNvbmRpdGlvbkdlbmVyYXRvci5qYXZh)
 | `83.8710% <0.0000%> (ø)` | |
   | 
[...ontracts/ast/visitor/AnnotationClosureVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/3371?src=pr&el=tree&filepath=subprojects%2Fgroovy-contracts%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fcontracts%2Fast%2Fvisitor%2FAnnotationClosureVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWNvbnRyYWN0cy9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZ3Jvb3Z5L2NvbnRyYWN0cy9hc3QvdmlzaXRvci9Bbm5vdGF0aW9uQ2xvc3VyZVZpc2l0b3IuamF2YQ==)
 | `89.7638% <72.9730%> (-1.8060%)` | :arrow_down: |
   
   ... and [9 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3371/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: @Requires and @Ensures on interface methods with a body fail
> ------------------------------------------------------------------------------
>
>                 Key: GROOVY-12843
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12843
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-contracts
>    Affects Versions: 6.0.0, 6.0.1
>            Reporter: Paul King
>            Priority: Major
>
> {{@Requires}} and {{@Ensures}} work on an abstract interface method, where 
> the check is woven into the implementing class. On an interface method that 
> has a body (a default or static method) they compile in dynamic code but 
> every call fails, whether or not the condition holds. Under 
> {{@CompileStatic}} they don't compile.
> {code:groovy}
> import groovy.contracts.*
> interface Limited {
>     int getMax()
>     @Requires({ x <= max })
>     @Ensures({ result <= max })
>     default int twice(int x) { x * 2 }
> }
> class Five implements Limited {
>     int getMax() { 5 }
> }
> assert new Five().twice(2) == 4
> {code}
> The call fails with:
> {noformat}
> groovy.lang.MissingPropertyException: No such property: $GCONTRACTS_ENABLED 
> for class: Five
> {noformat}
> With {{@CompileStatic}} on the interface, compilation fails with:
> {noformat}
> Access to Limited#$GCONTRACTS_ENABLED is forbidden
> {noformat}
> A contract expressed in terms of the method's parameters, its result and 
> other interface members is well defined here: an implementer supplies the 
> members, and the contract holds for whatever they return.
> h3. Cause
> The condition class is generated and the check is woven into the interface 
> method, but the check is guarded by a {{$GCONTRACTS_ENABLED}} field that 
> {{ClosureExpressionEvaluationASTTransformation}} adds only to classes.
> Declaring the field by hand as an interface constant makes the example work, 
> but a postcondition has a second problem. Every instance method with 
> {{@Ensures}} calls {{$_gc_computeOldVariables()}}, even when {{old}} isn't 
> used. That method exists only on classes compiled with contracts, so an 
> implementer such as a map coerced to the interface fails with a 
> {{MissingMethodException}}. Where the method does exist, {{old}} holds the 
> implementer's fields rather than the interface's properties, so {{old.n}} is 
> null unless the implementer happens to have a field named {{n}}.
> h3. Proposed behaviour
> * {{@Requires}} and {{@Ensures}} are checked on default and static interface 
> methods, in dynamic and statically compiled code. This includes calls through 
> a lambda, a coerced map, an enum, a record or a separately compiled 
> implementer, and methods that override the default.
> * In a postcondition of a default method, {{old.name}} is the entry value of 
> a parameter, or of a property of the interface read through its getter. How 
> the implementer stores the property doesn't matter.
> * Any other {{old.name}} in such a postcondition is a compile error.
> * A postcondition inherited from a separately compiled interface may use an 
> {{old}} name that the compiler can't see when an interface overrides the 
> method. Reading that name throws an {{IllegalStateException}} that says which 
> name was not recorded and how to fix it. Inherited contracts that don't use 
> {{old}} are unaffected.
> * Enabling and disabling assertions goes by the name of the interface that 
> declares the method.
> h3. Compatibility
> An interface that declares a method with a body and has contracts gains a 
> synthetic {{public static final}} field, {{$GCONTRACTS_ENABLED}}. Generated 
> code links to one new {{@GroovyABI}} constructor, 
> {{org.apache.groovy.contracts.util.OldProperties}}. Classes, traits and 
> interfaces with only abstract methods are unchanged.
> h3. Not covered
> * A class that overrides a contracted interface method still takes {{old}} 
> from its own fields, as it does now for abstract methods.
> * A mutable value that can't be cloned, such as a property of type {{List}}, 
> is recorded by reference, as parameters are now.
> * Traits. A contract on a trait method with a body is rejected since 
> GROOVY-12741.



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

Reply via email to