From 625858c8310d15ab5bdba8f0d9d797569f6e781e Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Wed, 24 Feb 2021 17:11:52 -0600 Subject: [PATCH] GROOVY-6938 --- .../core/tests/xform/TypeCheckedTests.java | 41 +++++++++++++++++++ .../stc/StaticTypeCheckingVisitor.java | 4 +- .../stc/StaticTypeCheckingVisitor.java | 4 +- .../stc/StaticTypeCheckingVisitor.java | 4 +- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java index 7f7c8e0ca3..95f8291ea9 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java @@ -293,6 +293,47 @@ public void testTypeChecked6882() { runConformTest(sources, "CC"); } + @Test + public void testTypeChecked6938() { + //@formatter:off + String[] sources = { + "Main.groovy", + "import groovy.transform.ASTTest\n" + + "import groovy.transform.TypeChecked\n" + + "import org.codehaus.groovy.ast.expr.MethodCallExpression\n" + + "import static org.codehaus.groovy.transform.stc.StaticTypesMarker.INFERRED_TYPE\n" + + + "@TypeChecked\n" + + "class G extends J {\n" + + " Integer doSomething() {\n" + + " @ASTTest(phase=CLASS_GENERATION, value={\n" + + " def expr = node.rightExpression\n" + + " assert expr instanceof MethodCallExpression\n" + + " assert expr.objectExpression.text == 'super'\n" + + + " def type = expr.objectExpression.getNodeMetaData(INFERRED_TYPE)\n" + + " assert type.toString(false) == 'J '\n" + // was "J" + " type = node.leftExpression.getNodeMetaData(INFERRED_TYPE)\n" + + " assert type.toString(false) == 'java.lang.Integer'\n" + + " })\n" + + " def result = super.doSomething()\n" + + " return result\n" + + " }\n" + + "}\n" + + "print new G().doSomething()\n", + + "J.java", + "public class J {\n" + + " public T doSomething() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }; + //@formatter:on + + runConformTest(sources, "null"); + } + @Test public void testTypeChecked7333() { //@formatter:off diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 1193dddd48..9b32192a0e 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5318,8 +5318,8 @@ private ClassNode getTypeFromClosureArguments(Parameter parameter, TypeCheckingC return null; } - private ClassNode makeSuper() { - return makeType(typeCheckingContext.getEnclosingClassNode().getSuperClass(), typeCheckingContext.isInStaticContext); + private ClassNode makeSuper() { // GRECLIPSE edit -- GROOVY-6938 + return makeType(typeCheckingContext.getEnclosingClassNode().getUnresolvedSuperClass(), typeCheckingContext.isInStaticContext); } private ClassNode makeThis() { diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 0e79125fe6..af4c79f766 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5098,8 +5098,8 @@ private static ClassNode makeSelf(final ClassNode trait) { return selfType; } - private ClassNode makeSuper() { - return makeType(typeCheckingContext.getEnclosingClassNode().getSuperClass(), typeCheckingContext.isInStaticContext); + private ClassNode makeSuper() { // GRECLIPSE edit -- GROOVY-6938 + return makeType(typeCheckingContext.getEnclosingClassNode().getUnresolvedSuperClass(), typeCheckingContext.isInStaticContext); } private ClassNode makeThis() { diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index c2cae298ec..9acd096296 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -5064,8 +5064,8 @@ private static ClassNode makeSelf(final ClassNode trait) { return selfType; } - private ClassNode makeSuper() { - return makeType(typeCheckingContext.getEnclosingClassNode().getSuperClass(), typeCheckingContext.isInStaticContext); + private ClassNode makeSuper() { // GRECLIPSE edit -- GROOVY-6938 + return makeType(typeCheckingContext.getEnclosingClassNode().getUnresolvedSuperClass(), typeCheckingContext.isInStaticContext); } private ClassNode makeThis() {