You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/09/20 00:47:43 UTC

[groovy] branch GROOVY_2_5_X updated: GROOVY-8103: add test case

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

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


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new d21c265  GROOVY-8103: add test case
d21c265 is described below

commit d21c2654a23163bad87b48cf7bad3fb6d75d7b04
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Sep 17 17:36:32 2020 -0500

    GROOVY-8103: add test case
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +-
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 37 +++++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 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 1234ce1..b5f8d4f 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3431,7 +3431,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                                 returnType = md.getType();
                             }
                         }
-                        if (typeCheckMethodsWithGenericsOrFail(chosenReceiver.getType(), args, mn.get(0), call)) {
+                        if (typeCheckMethodsWithGenericsOrFail(chosenReceiver.getType(), args, directMethodCallCandidate, call)) {
                             returnType = adjustWithTraits(directMethodCallCandidate, chosenReceiver.getType(), args, returnType);
 
                             storeType(call, returnType);
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 614957a..cf6880b 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1136,7 +1136,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
     }
 
     // GROOVY-5724
-    void testJunitHamcrest() {
+    void testJUnitHamcrest() {
         assertScript '''
             public class Matcher<T> {}
             public <T> void assertThat(T obj, Matcher<T> matcher) {}
@@ -1147,6 +1147,41 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-8103
+    void testJUnitFestAssert() {
+        assertScript '''
+            import static Fluent.*
+            import Util.Ours
+
+            class Fluent {
+                static FluentAPI  fluent(String s) { return new FluentAPI() }
+                static <T extends FluentExtension> T fluent(T t) { return t }
+            }
+
+            class FluentAPI {
+                FluentAPI isEqualTo(String s) { return this }
+            }
+
+            interface FluentExtension {
+            }
+
+            class Util {
+                static class Ours implements FluentExtension {
+                    Ours isSimilarTo(String json) { return this }
+                }
+                static Ours factory(String json) { new Ours() }
+            }
+
+            void test() {
+                fluent('string').isEqualTo('x') // fine
+                fluent(new Ours()).isSimilarTo('') // fine
+                fluent(Util.factory('{}')).isSimilarTo('{"key":"val"}') // STC error
+            }
+
+            test()
+        '''
+    }
+
     // GROOVY-5836
     void testShouldFindMethodEvenIfUsingGenerics() {
         assertScript '''