Skip to content

Commit

Permalink
GROOVY-10341
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 17, 2021
1 parent 0b1d279 commit dfe32b0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4747,6 +4747,33 @@ public void testTypeChecked10339() {
"----------\n");
}

@Test
public void testTypeChecked10341() {
//@formatter:off
String[] sources = {
"Main.groovy",
"abstract class A {\n" +
" abstract def m()\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"class C extends A {\n" +
" @Override\n" +
" def m() {\n" +
" super.m()\n" +
" }\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 8)\n" +
"\tsuper.m()\n" +
"\t^^^^^^^^^\n" +
"Groovy:[Static type checking] - Abstract method m() cannot be called directly\n" +
"----------\n");
}

@Test
public void testTypeChecked10344() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4312,6 +4312,10 @@ public void visitMethodCallExpression(MethodCallExpression call) {
ClassNode owner = directMethodCallCandidate.getDeclaringClass();
addStaticTypeError("Non static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
}
// GRECLIPSE add -- GROOVY-10341
else if (directMethodCallCandidate.isAbstract() && objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isSuperExpression())
addStaticTypeError("Abstract method " + toMethodParametersString(directMethodCallCandidate.getName(), extractTypesFromParameters(directMethodCallCandidate.getParameters())) + " cannot be called directly", call);
// GRECLIPSE end
if (chosenReceiver == null) {
chosenReceiver = Receiver.make(directMethodCallCandidate.getDeclaringClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3963,6 +3963,10 @@ public void visitMethodCallExpression(final MethodCallExpression call) {
ClassNode owner = directMethodCallCandidate.getDeclaringClass();
addStaticTypeError("Non static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
}
// GRECLIPSE add -- GROOVY-10341
else if (directMethodCallCandidate.isAbstract() && isSuperExpression(objectExpression))
addStaticTypeError("Abstract method " + toMethodParametersString(directMethodCallCandidate.getName(), extractTypesFromParameters(directMethodCallCandidate.getParameters())) + " cannot be called directly", call);
// GRECLIPSE end
if (chosenReceiver == null) {
chosenReceiver = Receiver.make(directMethodCallCandidate.getDeclaringClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3478,6 +3478,8 @@ && implementsInterfaceOrIsSubclassOf(receiverType, node.getDeclaringClass()))) {
if (!targetMethodCandidate.isStatic() && !isClassType(declaringClass)
&& 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);
}
if (chosenReceiver == null) {
chosenReceiver = Receiver.make(declaringClass);
Expand Down

0 comments on commit dfe32b0

Please sign in to comment.