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

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

Copilot commented on code in PR #2577:
URL: https://github.com/apache/groovy/pull/2577#discussion_r3329767812


##########
subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/LoopVariantASTTransformation.java:
##########
@@ -129,6 +129,11 @@ public void visit(final ASTNode[] nodes, final SourceUnit 
source) {
 
         // Inject: save at start, check at end
         injectAtLoopBodyStartAndEnd(loopStatement, savePrev, block(saveCurr, 
decreaseCheck));
+
+        // The variant closure lived inside an annotation, so its variable 
references were never
+        // resolved; re-run scope analysis now that they are real loop-body 
statements so that
+        // @TypeChecked/@CompileStatic can see their declared types.
+        LoopContractSupport.resolveVariableScopes(source);

Review Comment:
   `LoopContractSupport` is not defined anywhere in the repo, so this will fail 
compilation. To re-run scope analysis after moving the variant expression out 
of the annotation closure, invoke `VariableScopeVisitor` on the SourceUnit’s 
classes (similar to other AST transforms in core Groovy).



##########
subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/LoopInvariantASTTransformation.java:
##########
@@ -98,6 +98,11 @@ public void visit(final ASTNode[] nodes, final SourceUnit 
source) {
         wrapped.setSourcePosition(annotation);
 
         injectAtLoopBodyStart(loopStatement, wrapped);
+
+        // The invariant closure lived inside an annotation, so its variable 
references were never
+        // resolved; re-run scope analysis now that they are real loop-body 
statements so that
+        // @TypeChecked/@CompileStatic can see their declared types.
+        LoopContractSupport.resolveVariableScopes(source);

Review Comment:
   `LoopContractSupport` does not exist in this module/package, so this call 
will not compile. If the goal is to re-run variable scope analysis after 
injecting statements (so `@TypeChecked/@CompileStatic` can see local variable 
references), call `VariableScopeVisitor` directly (as done in several core 
Groovy AST transforms).





> groovy-contracts loop @Invariants and @Decreases fail under @TypeChecked
> ------------------------------------------------------------------------
>
>                 Key: GROOVY-12053
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12053
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to