Skip to content

Commit

Permalink
GROOVY-10494
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 17, 2022
1 parent ec804d5 commit 9d9590a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {\n" +
" default void m(T t) {\n" +
" println t\n" +
" }\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"class C implements I<String> {\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"}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9d9590a

Please sign in to comment.