groovy git commit: GROOVY-8342: Static compilation error with a method returning an array in a type parameter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: GROOVY-8342: Static compilation error with a method returning an array in a type parameter

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 815cc4b88 -> ec9da97b0


GROOVY-8342: Static compilation error with a method returning an array in a type parameter


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

Branch: refs/heads/master
Commit: ec9da97b0281643341d1e19e5cc2ac664fc5c2e5
Parents: 815cc4b
Author: Paul King <[hidden email]>
Authored: Thu Oct 11 11:32:13 2018 +1000
Committer: Paul King <[hidden email]>
Committed: Thu Oct 11 11:34:13 2018 +1000

----------------------------------------------------------------------
 .../stc/StaticTypeCheckingSupport.java          | 16 +++++----
 src/test/groovy/bugs/Groovy8342Bug.groovy       | 38 ++++++++++++++++++++
 2 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ec9da97b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 0377119..d6ba828 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1916,12 +1916,16 @@ public abstract class StaticTypeCheckingSupport {
             return newGT;
         }
         ClassNode type = gt.getType();
-        if (type.getGenericsTypes() == null) return gt;
-        ClassNode newType = type.getPlainNodeReference();
-        newType.setGenericsPlaceHolder(type.isGenericsPlaceHolder());
-        newType.setGenericsTypes(applyGenericsContext(spec, type.getGenericsTypes()));
-        GenericsType newGT = new GenericsType(newType);
-        return newGT;
+        ClassNode newType;
+        if (type.isArray()) {
+            newType = applyGenericsContext(spec, type.getComponentType()).makeArray();
+        } else {
+            if (type.getGenericsTypes()==null) return gt;
+            newType = type.getPlainNodeReference();
+            newType.setGenericsPlaceHolder(type.isGenericsPlaceHolder());
+            newType.setGenericsTypes(applyGenericsContext(spec, type.getGenericsTypes()));
+        }
+        return new GenericsType(newType);
     }
 
     private static boolean hasNonTrivialBounds(GenericsType gt) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/ec9da97b/src/test/groovy/bugs/Groovy8342Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8342Bug.groovy b/src/test/groovy/bugs/Groovy8342Bug.groovy
new file mode 100644
index 0000000..53087ac
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8342Bug.groovy
@@ -0,0 +1,38 @@
+/*
+ *  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 gls.CompilableTestSupport
+
+class Groovy8342Bug extends CompilableTestSupport {
+    void testCorrectHandlingForArrayOfGenericType() {
+        shouldCompile '''
+            @groovy.transform.CompileStatic
+            class ArrayGenericsIssue {
+                static void main(String[] args) {
+                    Optional<Integer[]> value = testArrayMethod(1)
+                }
+
+                static <E> Optional<E[]> testArrayMethod(E ignored) {
+                    return Optional.empty()
+                }
+            }
+        '''
+    }
+}