This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
     new e32dfaa43a GROOVY-10341: STC: error for `super.abstractMethod()`
e32dfaa43a is described below

commit e32dfaa43a0869ee4a8f066a97c3d5f28b8e3ae0
Author: Eric Milles <[email protected]>
AuthorDate: Fri Dec 8 15:35:41 2023 -0600

    GROOVY-10341: STC: error for `super.abstractMethod()`
    
    3_0_X backport
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  7 +++++
 .../groovy/transform/stc/MethodCallsSTCTest.groovy | 36 +++++++++++++++++++++-
 2 files changed, 42 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 f094066b2c..807b128f1c 100644
--- 
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ 
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3570,6 +3570,13 @@ public class StaticTypeCheckingVisitor extends 
ClassCodeVisitorSupport {
                         if (!directMethodCallCandidate.isStatic() && 
!(declaringClass.equals(CLASS_Type) || declaringClass.equals(OBJECT_TYPE)) // 
GROOVY-10939
                                 && receiver.equals(CLASS_Type) && 
chosenReceiver.getData() == null && 
!Boolean.TRUE.equals(call.getNodeMetaData(DYNAMIC_RESOLUTION))) {
                             addStaticTypeError("Non-static method " + 
prettyPrintTypeName(declaringClass) + "#" + directMethodCallCandidate.getName() 
+ " cannot be called from static context", call);
+                        } else if (directMethodCallCandidate.isAbstract() && 
isSuperExpression(objectExpression)) { // GROOVY-10341
+                            String target = 
toMethodParametersString(directMethodCallCandidate.getName(), 
extractTypesFromParameters(directMethodCallCandidate.getParameters()));
+                            if 
(Traits.hasDefaultImplementation(directMethodCallCandidate)) { // GROOVY-10494
+                                addStaticTypeError("Default method " + target 
+ " requires qualified super", call);
+                            } else {
+                                addStaticTypeError("Abstract method " + target 
+ " cannot be called directly", call);
+                            }
                         }
 
                         ClassNode returnType = 
getType(directMethodCallCandidate);
diff --git a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy 
b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
index 6907fe9afd..b4d62dfca3 100644
--- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
@@ -18,6 +18,7 @@
  */
 package groovy.transform.stc
 
+import groovy.test.NotYetImplemented
 import org.codehaus.groovy.control.MultipleCompilationErrorsException
 
 import static 
org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder.withConfig
@@ -331,7 +332,7 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase 
{
         '''
     }
 
-    void testCallToSuperDefault() {
+    void testCallToSuperDefault1() {
         assertScript '''
             interface I<T> {
                 default m(T t) {
@@ -348,6 +349,23 @@ class MethodCallsSTCTest extends 
StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10494
+    @NotYetImplemented
+    void testCallToSuperDefault2() {
+        shouldFailWithMessages '''
+            interface I<T> {
+                default void m(T t) {
+                }
+            }
+            class C implements I<String> {
+                @Override void m(String s) {
+                    super.m(s)
+                }
+            }
+        ''',
+        'Default method m(T) requires qualified super'
+    }
+
     // GROOVY-10922
     void testCallToSuperGenerated() {
         assertScript '''
@@ -1636,6 +1654,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 '''

Reply via email to