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 2018/03/10 13:44:15 UTC
groovy git commit: GROOVY-8439: @CompileStatic cannot compile generic
class's static method
Repository: groovy
Updated Branches:
refs/heads/master a8b9be9e6 -> e154c3e56
GROOVY-8439: @CompileStatic cannot compile generic class's static method
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/e154c3e5
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/e154c3e5
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/e154c3e5
Branch: refs/heads/master
Commit: e154c3e560e998e158985316566c7e321579b193
Parents: a8b9be9
Author: danielsun1106 <re...@hotmail.com>
Authored: Sat Mar 10 21:43:49 2018 +0800
Committer: danielsun1106 <re...@hotmail.com>
Committed: Sat Mar 10 21:43:49 2018 +0800
----------------------------------------------------------------------
.../stc/StaticTypeCheckingVisitor.java | 8 +++-
src/test/groovy/bugs/Groovy8439Bug.groovy | 49 ++++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/e154c3e5/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
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 c3f0148..7881176 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2738,13 +2738,19 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
}
boolean lastArg = i == length - 1;
+
if (lastArg && inferredType.isArray()) {
if (inferredType.getComponentType().equals(originType)) {
inferredType = originType;
}
} else if (!typeCheckMethodArgumentWithGenerics(originType, inferredType, lastArg)) {
- addError("Expected parameter of type "+ inferredType.toString(false)+" but got "+originType.toString(false), closureParam.getType());
+ if (!isGenericsPlaceHolderOrArrayOf(originType)) { // the original type is not generics placeholder, use original type directly. See GROOVY-8439
+ inferredType = originType;
+ } else {
+ addError("Expected parameter of type "+ inferredType.toString(false)+" but got "+originType.toString(false), closureParam.getType());
+ }
}
+
typeCheckingContext.controlStructureVariables.put(closureParam, inferredType);
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/e154c3e5/src/test/groovy/bugs/Groovy8439Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8439Bug.groovy b/src/test/groovy/bugs/Groovy8439Bug.groovy
new file mode 100644
index 0000000..ccca137
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8439Bug.groovy
@@ -0,0 +1,49 @@
+/*
+ * 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 Groovy8439Bug extends GroovyTestCase {
+ void testSTCGenerics() {
+ assertScript '''
+ import groovy.transform.CompileStatic
+ @CompileStatic
+ class Test<T extends Task> {
+ static def something(Task task, Collection<BaseVariant> variants) {
+ variants.collectMany { it.sourceFolders }.collect { ConfigurableFileTree tree ->
+ task.getBuildDir().toPath().relativize(tree.dir.toPath()).toString() + File.separator
+ }
+ }
+ }
+
+ interface BaseVariant {
+ List<ConfigurableFileTree> getSourceFolders()
+ }
+
+ interface ConfigurableFileTree {
+ File getDir()
+ }
+
+ interface Task {
+ File getBuildDir()
+ }
+
+ Test.something(null, [])
+ '''
+ }
+}