From 9d9590aefa2ba00b3898d8a8e6c9444afffe8d95 Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 17 Mar 2022 15:04:22 -0500 Subject: [PATCH] GROOVY-10494 --- .../core/tests/xform/TypeCheckedTests.java | 30 +++++++++++++++++++ .../stc/StaticTypeCheckingVisitor.java | 7 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) 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 ec52388159..3d2064cf34 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 @@ -5328,6 +5328,36 @@ public void testTypeChecked10482b() { runConformTest(sources); } + @Test + public void testTypeChecked10494() { + assumeTrue(isAtLeastGroovy(40) && isParrotParser()); + + //@formatter:off + String[] sources = { + "Main.groovy", + "interface I {\n" + + " default void m(T t) {\n" + + " println t\n" + + " }\n" + + "}\n" + + "@groovy.transform.TypeChecked\n" + + "class C implements I {\n" + + " @Override void m(String s) {\n" + + " super.m(s)\n" + + " }\n" + + "}\n", + }; + //@formatter:on + + runNegativeTest(sources, + "----------\n" + + "1. ERROR in Main.groovy (at line 9)\n" + + "\tsuper.m(s)\n" + + "\t^^^^^^^^^^\n" + + "Groovy:[Static type checking] - Default method m(T) requires qualified super\n" + + "----------\n"); + } + @Test public void testTypeChecked10499() { for (String bounds : new String[] {"?", "Y", "? extends Y"}) { 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 d84d476306..fe2476ba97 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 @@ -3524,7 +3524,12 @@ && implementsInterfaceOrIsSubclassOf(receiverType, node.getDeclaringClass()))) { && 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);