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 2022/03/17 20:14:32 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10494: STC: indicate qualifier required for super.defaultMethod()
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 432e75a GROOVY-10494: STC: indicate qualifier required for super.defaultMethod()
432e75a is described below
commit 432e75a7fdf10e9ccb92c2e2be42c8d6682ea566
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Mar 17 14:53:29 2022 -0500
GROOVY-10494: STC: indicate qualifier required for super.defaultMethod()
---
.../transform/stc/StaticTypeCheckingVisitor.java | 7 ++++-
.../groovy/transform/stc/MethodCallsSTCTest.groovy | 31 ++++++++++++++++++++++
2 files changed, 37 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 84edb7a..c0cfd3b 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3495,7 +3495,12 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
&& 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);
+ String target = toMethodParametersString(targetMethodCandidate.getName(), extractTypesFromParameters(targetMethodCandidate.getParameters()));
+ if (Traits.hasDefaultImplementation(targetMethodCandidate)) { // GROOVY-10494
+ addStaticTypeError("Default method " + target + " requires qualified super", call);
+ } else {
+ addStaticTypeError("Abstract method " + target + " 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 4d29461..779c84f 100644
--- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
@@ -269,6 +269,37 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10494
+ void testCallToSuperDefault() {
+ assertScript '''
+ interface I<T> {
+ default m(T t) {
+ return t
+ }
+ }
+ class C implements I<String> {
+ @Override m(String s) {
+ I.super.m(s)
+ }
+ }
+ String result = new C().m('works')
+ assert result == 'works'
+ '''
+
+ 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'
+ }
+
void testMethodCallFromSuperOwner() {
assertScript '''
class Child extends groovy.transform.stc.MethodCallsSTCTest.GroovyPage {