You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/03/02 23:01:34 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-9903: incomplete DelegatesTo parameters error links to annotation

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new 60695d6  GROOVY-9903: incomplete DelegatesTo parameters error links to annotation
60695d6 is described below

commit 60695d63e6295aef5ebec5cffeb92e0670c07992
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Jan 20 15:57:26 2021 -0600

    GROOVY-9903: incomplete DelegatesTo parameters error links to annotation
    
    Conflicts:
    	src/testFixtures/groovy/groovy/transform/stc/StaticTypeCheckingTestCase.groovy
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +-
 .../groovy/transform/stc/DelegatesToSTCTest.groovy | 29 ++++++++++------------
 .../stc/StaticTypeCheckingTestCase.groovy          |  7 +++---
 3 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 0837853..883d05b 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3214,7 +3214,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                         }
                     }
                     if (expression.getNodeMetaData(DELEGATION_METADATA) == null) {
-                        addError("Not enough arguments found for a @DelegatesTo method call. Please check that you either use an explicit class or @DelegatesTo.Target with a correct id", arguments);
+                        addError("Not enough arguments found for a @DelegatesTo method call. Please check that you either use an explicit class or @DelegatesTo.Target with a correct id", annotation);
                     }
                 }
             }
diff --git a/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy b/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
index 8480ac5..47ad549 100644
--- a/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
+++ b/src/test/groovy/transform/stc/DelegatesToSTCTest.groovy
@@ -280,24 +280,21 @@ class DelegatesToSTCTest extends StaticTypeCheckingTestCase {
     }
 
     void testShouldFailDelegateToParameterIfNoTargetSpecified() {
-        shouldFailWithMessages '''
-        class Foo {
-            boolean called = false
-            def foo() { called = true }
-        }
+        shouldFailWithMessages '''\
+            class Foo {
+                boolean called = false
+                def bar() { called = true }
+            }
 
-        def with(Object target, @DelegatesTo Closure arg) {
-            arg.delegate = target
-            arg()
-        }
+            def m(Object o, @DelegatesTo Closure c) {
+                c.delegate = o
+                c.call()
+            }
 
-        def test() {
-            def obj = new Foo()
-            with(obj) { foo() }
-            assert obj.called
-        }
-        test()
-        ''', 'Not enough arguments found for a @DelegatesTo method call', 'Cannot find matching method'
+            def foo = new Foo()
+            m(foo) { -> bar() }
+            assert foo.called
+        ''', 'Not enough arguments found for a @DelegatesTo method call', '@ line 6, column 29', 'Cannot find matching method'
     }
 
     void testDelegatesToWithSetter() {
diff --git a/src/test/groovy/transform/stc/StaticTypeCheckingTestCase.groovy b/src/test/groovy/transform/stc/StaticTypeCheckingTestCase.groovy
index 8fde8ef..7d5ebda 100644
--- a/src/test/groovy/transform/stc/StaticTypeCheckingTestCase.groovy
+++ b/src/test/groovy/transform/stc/StaticTypeCheckingTestCase.groovy
@@ -84,14 +84,13 @@ abstract class StaticTypeCheckingTestCase extends GroovyTestCase {
                     it instanceof SyntaxErrorMessage && it.cause.message.contains(message)
                 }
             }
-            if (success && mce.errorCollector.errorCount!=messages.length) {
-                throw new AssertionError("Expected error messages were found, but compiler threw additional errors : " + mce.toString())
+            if (success && mce.errorCollector.errorCount > messages.length) {
+                throw new AssertionError("Expected error messages were found, but compiler threw additional errors : $mce")
             }
             if (!success) {
-                throw new AssertionError("Not all expected error messages were found, compiler threw these errors : " + mce.toString())
+                throw new AssertionError("Not all expected error messages were found, compiler threw these errors : $mce")
             }
         }
         if (!success) throw new AssertionError("Test passed but should have failed with messages [$messages]")
     }
-
 }