You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/02/29 07:06:36 UTC

[groovy] 01/03: add an IF statement in the method check genercis

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

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

commit cb0cd8e7de7da6bcaa05e6a31eb282d3c878f9d2
Author: gyd_lhw <83...@qq.com>
AuthorDate: Tue Feb 25 14:42:11 2020 +0000

    add an IF statement in the method check genercis
    
    (cherry picked from commit 8cae0302557af707633791eb33080543cf715679)
---
 .../java/org/codehaus/groovy/ast/GenericsType.java |  4 +-
 src/test/groovy/bugs/Groovy9412Bug.groovy          | 46 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 700204f..c697b2e 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -291,7 +291,9 @@ public class GenericsType extends ASTNode {
     private boolean checkGenerics(final ClassNode classNode) {
         ClassNode lowerBound = getLowerBound();
         if (lowerBound != null) {
-            return compareGenericsWithBound(classNode, lowerBound);
+            if (!lowerBound.redirect().isUsingGenerics()) {
+                return compareGenericsWithBound(classNode, lowerBound);
+            }
         }
         ClassNode[] upperBounds = getUpperBounds();
         if (upperBounds != null) {
diff --git a/src/test/groovy/bugs/Groovy9412Bug.groovy b/src/test/groovy/bugs/Groovy9412Bug.groovy
new file mode 100644
index 0000000..96ad608
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9412Bug.groovy
@@ -0,0 +1,46 @@
+/*
+ *  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
+
+import groovy.test.GroovyTestCase;
+class Groovy9412Bug extends GroovyTestCase {
+    void testProtectedFieldInClosureInEnum(){
+        assertScript '''
+    import groovy.transform.TypeChecked
+
+        @TypeChecked
+        class MyClass {
+
+            interface Foo {}
+
+            enum Bar implements Foo {
+                AA
+            }
+
+            void F() {
+                List<Foo> g = []
+                g.add(Bar.AA)
+            }
+        }
+
+    assert new MyClass()
+    '''
+
+    }
+}