groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: GROOVY-7985: Wrong "incompatible generic type" error
Date Fri, 11 May 2018 06:07:30 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 795e2540c -> 9f14993d9


GROOVY-7985: Wrong "incompatible generic type" error


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/9f14993d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/9f14993d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/9f14993d

Branch: refs/heads/master
Commit: 9f14993d9e260a1277311fad78d13bd6f4c8c95f
Parents: 795e254
Author: sunlan <sunlan@apache.org>
Authored: Fri May 11 14:04:57 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri May 11 14:04:57 2018 +0800

----------------------------------------------------------------------
 .../groovy/ast/tools/GenericsUtils.java         | 33 +++++++----
 src/test/groovy/bugs/Groovy7985Bug.groovy       | 62 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9f14993d/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
index 98057d0..27f2bd9 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GenericsUtils.java
@@ -165,6 +165,8 @@ public class GenericsUtils {
                     "\nExpected: " + node.getName() + toGenericTypesString(redirectGenericsTypes)
+
                     "\nSupplied: " + node.getName() + toGenericTypesString(parameterized));
         }
+
+        List<GenericsType> valueList = new LinkedList<>();
         for (int i = 0; i < redirectGenericsTypes.length; i++) {
             GenericsType redirectType = redirectGenericsTypes[i];
             if (redirectType.isPlaceholder()) {
@@ -172,21 +174,26 @@ public class GenericsUtils {
                 if (!map.containsKey(name)) {
                     GenericsType value = parameterized[i];
                     map.put(name, value);
-                    if (value.isWildcard()) {
-                        ClassNode lowerBound = value.getLowerBound();
-                        if (lowerBound != null) {
-                            extractPlaceholders(lowerBound, map);
-                        }
-                        ClassNode[] upperBounds = value.getUpperBounds();
-                        if (upperBounds != null) {
-                            for (ClassNode upperBound : upperBounds) {
-                                extractPlaceholders(upperBound, map);
-                            }
-                        }
-                    } else if (!value.isPlaceholder()) {
-                        extractPlaceholders(value.getType(), map);
+
+                    valueList.add(value);
+                }
+            }
+        }
+
+        for (GenericsType value : valueList) {
+            if (value.isWildcard()) {
+                ClassNode lowerBound = value.getLowerBound();
+                if (lowerBound != null) {
+                    extractPlaceholders(lowerBound, map);
+                }
+                ClassNode[] upperBounds = value.getUpperBounds();
+                if (upperBounds != null) {
+                    for (ClassNode upperBound : upperBounds) {
+                        extractPlaceholders(upperBound, map);
                     }
                 }
+            } else if (!value.isPlaceholder()) {
+                extractPlaceholders(value.getType(), map);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9f14993d/src/test/groovy/bugs/Groovy7985Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7985Bug.groovy b/src/test/groovy/bugs/Groovy7985Bug.groovy
new file mode 100644
index 0000000..e0b45b5
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7985Bug.groovy
@@ -0,0 +1,62 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+
+
+
+package groovy.bugs
+
+class Groovy7985Bug extends GroovyTestCase {
+    void test1() {
+        assertScript '''
+        import java.io.Serializable;
+        import java.util.Date;
+        import groovy.transform.CompileStatic
+
+        @CompileStatic
+        class Test {
+            Pair<Pair<String, Integer>, Pair<String, Integer>> doSmething()
{
+                def left = (Pair<String, Integer>) Pair.of("a", 1)
+                def right = (Pair<String, Integer>) Pair.of("b", 2)
+                return Pair.of(left, right)
+            }
+        }
+
+        @CompileStatic
+        class Pair<L, R> implements Serializable {
+            public static <L, R> Pair<L, R> of(final L left, final R right) {
+                return new Pair<>(left, right);
+            }
+
+            public final L left;
+            public final R right;
+
+            private Pair(final L left, final R right) {
+                this.left = left;
+                this.right = right;
+            }
+        }
+        
+        assert 'a' == new Test().doSmething().left.left
+        assert 1 == new Test().doSmething().left.right
+        assert 'b' == new Test().doSmething().right.left
+        assert 2 == new Test().doSmething().right.right
+        '''
+    }
+}


Mime
View raw message