You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/02/24 17:58:26 UTC
[groovy] branch master updated: GROOVY-6938: resolve type of
"super" expression including type arguments
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 444f6a5 GROOVY-6938: resolve type of "super" expression including type arguments
444f6a5 is described below
commit 444f6a5e7f10b75d43d94e7bb4fe771ae384c321
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Feb 24 11:23:08 2021 -0600
GROOVY-6938: resolve type of "super" expression including type arguments
---
.../transform/stc/StaticTypeCheckingVisitor.java | 2 +-
src/test/groovy/bugs/Groovy6938.groovy | 81 ++++++++++++++++++++++
.../groovy/bugs/groovy6938/Groovy6938Bug.groovy | 28 --------
src/test/groovy/bugs/groovy6938/L.groovy | 29 --------
src/test/groovy/bugs/groovy6938/LJava.java | 26 -------
5 files changed, 82 insertions(+), 84 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 a9a591b..ce53caa 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4955,7 +4955,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
private ClassNode makeSuper() {
- return makeType(typeCheckingContext.getEnclosingClassNode().getSuperClass(), typeCheckingContext.isInStaticContext);
+ return makeType(typeCheckingContext.getEnclosingClassNode().getUnresolvedSuperClass(), typeCheckingContext.isInStaticContext);
}
private ClassNode makeThis() {
diff --git a/src/test/groovy/bugs/Groovy6938.groovy b/src/test/groovy/bugs/Groovy6938.groovy
new file mode 100644
index 0000000..ae4f9b6
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy6938.groovy
@@ -0,0 +1,81 @@
+/*
+ * 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 org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+import org.junit.Test
+
+final class Groovy6938 {
+ @Test
+ void testPlaceholderResolutionForSuperMethodCall() {
+ def config = new CompilerConfiguration().tap {
+ jointCompilationOptions = [memStub: true]
+ targetDirectory = File.createTempDir()
+ }
+ File parentDir = File.createTempDir()
+ try {
+ def a = new File(parentDir, 'J.java')
+ a.write '''
+ public class J <T extends Number> {
+ public T doSomething() {
+ return null;
+ }
+ }
+ '''
+ def b = new File(parentDir, 'G.groovy')
+ b.write '''
+ import groovy.transform.ASTTest
+ import groovy.transform.CompileStatic
+ import org.codehaus.groovy.ast.expr.MethodCallExpression
+ import static org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_TYPE
+
+ @CompileStatic
+ class G extends J<Integer> {
+ Integer doSomething() {
+ @ASTTest(phase=CLASS_GENERATION, value={
+ def expr = node.rightExpression
+ assert expr instanceof MethodCallExpression
+ assert expr.objectExpression.text == 'super'
+
+ def type = expr.objectExpression.getNodeMetaData(INFERRED_TYPE)
+ assert type.toString(false) == 'J <Integer>' // was "J<T>"
+
+ type = node.leftExpression.getNodeMetaData(INFERRED_TYPE)
+ assert type.toString(false) == 'java.lang.Integer'
+ })
+ def result = super.doSomething()
+ return result
+ }
+ }
+ '''
+
+ def loader = new GroovyClassLoader(this.class.classLoader)
+ def cu = new JavaAwareCompilationUnit(config, loader)
+ cu.addSources(a, b)
+ cu.compile()
+
+ def result = loader.loadClass('G').newInstance().doSomething()
+ assert result == null
+ } finally {
+ parentDir.deleteDir()
+ config.targetDirectory.deleteDir()
+ }
+ }
+}
diff --git a/src/test/groovy/bugs/groovy6938/Groovy6938Bug.groovy b/src/test/groovy/bugs/groovy6938/Groovy6938Bug.groovy
deleted file mode 100644
index b76ddda..0000000
--- a/src/test/groovy/bugs/groovy6938/Groovy6938Bug.groovy
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.groovy6938
-
-import groovy.test.GroovyTestCase
-
-class Groovy6938Bug extends GroovyTestCase {
- void test() {
- assert null == new L().doSomething()
- }
-}
diff --git a/src/test/groovy/bugs/groovy6938/L.groovy b/src/test/groovy/bugs/groovy6938/L.groovy
deleted file mode 100644
index 5d80b72..0000000
--- a/src/test/groovy/bugs/groovy6938/L.groovy
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.groovy6938
-
-import groovy.transform.CompileStatic;
-
-@CompileStatic
-class L extends LJava<Integer> {
- Integer doSomething() {
- super.doSomething()
- }
-}
diff --git a/src/test/groovy/bugs/groovy6938/LJava.java b/src/test/groovy/bugs/groovy6938/LJava.java
deleted file mode 100644
index 90715b1..0000000
--- a/src/test/groovy/bugs/groovy6938/LJava.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.groovy6938;
-
-public class LJava <T extends Number> {
- public T doSomething() {
- return null;
- }
-}
\ No newline at end of file