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/11/17 17:54:23 UTC

[groovy] branch master updated: GROOVY-10341: STC: error for `super.abstractMethod()`

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 e97eab2  GROOVY-10341: STC: error for `super.abstractMethod()`
e97eab2 is described below

commit e97eab240d165b632e0cdbe5c6e685ac87dc2934
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Nov 17 11:54:14 2021 -0600

    GROOVY-10341: STC: error for `super.abstractMethod()`
---
 .../transform/stc/StaticTypeCheckingVisitor.java       |  2 ++
 .../groovy/transform/stc/MethodCallsSTCTest.groovy     | 18 +++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

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 cab64fe..482425d 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3469,6 +3469,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                         if (!targetMethodCandidate.isStatic() && !isClassType(declaringClass)
                                 && objectExpression instanceof ClassExpression && call.getNodeMetaData(DYNAMIC_RESOLUTION) == null) {
                             addStaticTypeError("Non-static method " + prettyPrintTypeName(declaringClass) + "#" + targetMethodCandidate.getName() + " cannot be called from static context", call);
+                        } else if (targetMethodCandidate.isAbstract() && isSuperExpression(objectExpression)) { // GROOVY-10341
+                            addStaticTypeError("Abstract method " + toMethodParametersString(targetMethodCandidate.getName(), extractTypesFromParameters(targetMethodCandidate.getParameters())) + " cannot be called directly", call);
                         }
                         if (chosenReceiver == null) {
                             chosenReceiver = Receiver.make(declaringClass);
diff --git a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
index 517a55d..481c496 100644
--- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
@@ -1356,6 +1356,22 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10341
+    void testCallAbstractSuperMethod() {
+        shouldFailWithMessages '''
+            abstract class Foo {
+                abstract def m()
+            }
+            class Bar extends Foo {
+                @Override
+                def m() {
+                    super.m()
+                }
+            }
+        ''',
+        'Abstract method m() cannot be called directly'
+    }
+
     // GROOVY-5810
     void testCallStaticSuperMethod() {
         assertScript '''
@@ -1368,7 +1384,7 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
 
             class Bottom extends Top {
                 public static foo() {
-                    super.foo() // compiles and creates StackOverFlow
+                    super.foo()
                 }
 
             }