Skip to content

Commit dfe32b0

Browse files
committed
GROOVY-10341
1 parent 0b1d279 commit dfe32b0

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java

+27
Original file line numberDiff line numberDiff line change
@@ -4747,6 +4747,33 @@ public void testTypeChecked10339() {
47474747
"----------\n");
47484748
}
47494749

4750+
@Test
4751+
public void testTypeChecked10341() {
4752+
//@formatter:off
4753+
String[] sources = {
4754+
"Main.groovy",
4755+
"abstract class A {\n" +
4756+
" abstract def m()\n" +
4757+
"}\n" +
4758+
"@groovy.transform.TypeChecked\n" +
4759+
"class C extends A {\n" +
4760+
" @Override\n" +
4761+
" def m() {\n" +
4762+
" super.m()\n" +
4763+
" }\n" +
4764+
"}\n",
4765+
};
4766+
//@formatter:on
4767+
4768+
runNegativeTest(sources,
4769+
"----------\n" +
4770+
"1. ERROR in Main.groovy (at line 8)\n" +
4771+
"\tsuper.m()\n" +
4772+
"\t^^^^^^^^^\n" +
4773+
"Groovy:[Static type checking] - Abstract method m() cannot be called directly\n" +
4774+
"----------\n");
4775+
}
4776+
47504777
@Test
47514778
public void testTypeChecked10344() {
47524779
//@formatter:off

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+4
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,10 @@ public void visitMethodCallExpression(MethodCallExpression call) {
43124312
ClassNode owner = directMethodCallCandidate.getDeclaringClass();
43134313
addStaticTypeError("Non static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
43144314
}
4315+
// GRECLIPSE add -- GROOVY-10341
4316+
else if (directMethodCallCandidate.isAbstract() && objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isSuperExpression())
4317+
addStaticTypeError("Abstract method " + toMethodParametersString(directMethodCallCandidate.getName(), extractTypesFromParameters(directMethodCallCandidate.getParameters())) + " cannot be called directly", call);
4318+
// GRECLIPSE end
43154319
if (chosenReceiver == null) {
43164320
chosenReceiver = Receiver.make(directMethodCallCandidate.getDeclaringClass());
43174321
}

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+4
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,10 @@ public void visitMethodCallExpression(final MethodCallExpression call) {
39633963
ClassNode owner = directMethodCallCandidate.getDeclaringClass();
39643964
addStaticTypeError("Non static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
39653965
}
3966+
// GRECLIPSE add -- GROOVY-10341
3967+
else if (directMethodCallCandidate.isAbstract() && isSuperExpression(objectExpression))
3968+
addStaticTypeError("Abstract method " + toMethodParametersString(directMethodCallCandidate.getName(), extractTypesFromParameters(directMethodCallCandidate.getParameters())) + " cannot be called directly", call);
3969+
// GRECLIPSE end
39663970
if (chosenReceiver == null) {
39673971
chosenReceiver = Receiver.make(directMethodCallCandidate.getDeclaringClass());
39683972
}

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java

+2
Original file line numberDiff line numberDiff line change
@@ -3478,6 +3478,8 @@ && implementsInterfaceOrIsSubclassOf(receiverType, node.getDeclaringClass()))) {
34783478
if (!targetMethodCandidate.isStatic() && !isClassType(declaringClass)
34793479
&& objectExpression instanceof ClassExpression && call.getNodeMetaData(DYNAMIC_RESOLUTION) == null) {
34803480
addStaticTypeError("Non-static method " + prettyPrintTypeName(declaringClass) + "#" + targetMethodCandidate.getName() + " cannot be called from static context", call);
3481+
} else if (targetMethodCandidate.isAbstract() && isSuperExpression(objectExpression)) { // GROOVY-10341
3482+
addStaticTypeError("Abstract method " + toMethodParametersString(targetMethodCandidate.getName(), extractTypesFromParameters(targetMethodCandidate.getParameters())) + " cannot be called directly", call);
34813483
}
34823484
if (chosenReceiver == null) {
34833485
chosenReceiver = Receiver.make(declaringClass);

0 commit comments

Comments
 (0)