You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2023/10/03 10:32:38 UTC
[groovy] 07/07: GROOVY-8299: typechecking needs to use receiver to decide on target method being valid
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit a3d7c7989d500bb086a5116b3e118e3b619c3112
Author: Jochen Theodorou <bl...@gmx.org>
AuthorDate: Sun Oct 1 16:46:25 2023 +0200
GROOVY-8299: typechecking needs to use receiver to decide on target method being valid
---
.../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 4 ++--
src/test/groovy/transform/stc/BugsSTCTest.groovy | 6 +++---
2 files changed, 5 insertions(+), 5 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 f702ae6a15..01ff32bc29 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3670,9 +3670,9 @@ out: if (mn.size() != 1) {
if (!targetMethod.isStatic() && !(isClassType(declaringClass) || isObjectType(declaringClass)) // GROOVY-10939: Class or Object
&& isClassType(receiver) && chosenReceiver.getData() == null && !Boolean.TRUE.equals(call.getNodeMetaData(DYNAMIC_RESOLUTION))) {
addStaticTypeError("Non-static method " + prettyPrintTypeName(declaringClass) + "#" + targetMethod.getName() + " cannot be called from static context", call);
- } else if (targetMethod.isAbstract() && isSuperExpression(objectExpression)) { // GROOVY-10341
+ } else if ((chosenReceiver.getType().isInterface() || targetMethod.isAbstract()) && isSuperExpression(objectExpression)) { // GROOVY-10341, GROOVY-8299
String target = toMethodParametersString(targetMethod.getName(), extractTypesFromParameters(targetMethod.getParameters()));
- if (Traits.hasDefaultImplementation(targetMethod)) { // GROOVY-10494
+ if (Traits.hasDefaultImplementation(targetMethod) || targetMethod.isDefault()) { // GROOVY-10494
addStaticTypeError("Default method " + target + " requires qualified super", call);
} else {
addStaticTypeError("Abstract method " + target + " cannot be called directly", call);
diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy
index 9c50a07d80..137092e46c 100644
--- a/src/test/groovy/transform/stc/BugsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy
@@ -1154,9 +1154,9 @@ class BugsSTCTest extends StaticTypeCheckingTestCase {
'''
}
- // GROOVY-9909
+ // GROOVY-9909 tests changed for GROOVY-8299
void testInvokeDefaultMethodFromDirectInterface() {
- assertScript '''
+ shouldFailWithMessages('''
class C implements groovy.transform.stc.Groovy9909 {
@Override String m() {
'it ' + super.m() // default method
@@ -1164,7 +1164,7 @@ class BugsSTCTest extends StaticTypeCheckingTestCase {
}
String result = new C().m()
assert result == 'it works'
- '''
+ ''', "Default method m() requires qualified super")
}
// GROOVY-8339, GROOVY-10109, GROOVY-10594