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

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

testlens-app[bot] commented on PR #3371:
URL: https://github.com/apache/groovy/pull/3371#issuecomment-7248127390

   ## 🚨 TestLens detected 2 failed tests 🚨
   
   ### Test Summary
   > [!TIP]
   > Inspect all details with the [TestLens 
CLI](https://testlens.app/docs/features/cli): `testlens pr 3371`
   
   #### [Build and test / lts \(25, 
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/46205182226/job/141166114756?pr=3371)
 > :test
   
   | Test | Runs | Flakiness |
   |---|---|--:|
   | GrabResolverTest > testResolverDefinitionResolvesDependency\(\) | ❌ | 
0% 🟢 |
   | GrabResolverTest > 
testResolverDefinitionResolvesDependencyWithShorthand\(\) | ❌ | 0% 🟢 |
   
   🏷️ Commit: 6ee1060893abc30b426bf5f58ca7261d0c1d876b
   ▶️ Tests:  50544 executed
   🟡 Checks: 8/24 completed
   
   ### Test Failures
   
   <details><summary><strong>GrabResolverTest > 
testResolverDefinitionResolvesDependency()</strong> (:test in <a 
href="https://github.com/apache/groovy/actions/runs/46205182226/job/141166114756?pr=3371";>Build
 and test / lts (25, ubuntu-latest)</a>)</summary>
   
   ```
   java.lang.AssertionError: Forked JVM for 
groovy.grape.GrabResolverTest#testResolverDefinitionResolvesDependency failed:
   org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
failed:
   General error during conversion: Error grabbing Grapes 

> 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