Skip to content
Permalink
Browse files
GROOVY-10357: STC: fix target type check for abstract method
  • Loading branch information
eric-milles committed Mar 14, 2022
1 parent d2f18c3 commit a80121ddb21440de718027c3997529081059dcce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
@@ -4178,6 +4178,7 @@ && isAssignment(enclosingExpression.getOperation().getType())
&& isTypeSource(expr, enclosingExpression.getRightExpression())) {
targetType = getDeclaredOrInferredType(enclosingExpression.getLeftExpression());
} else if (enclosingMethod != null
&& !enclosingMethod.isAbstract()
&& !enclosingMethod.isVoidMethod()
&& isTypeSource(expr, enclosingMethod)) {
targetType = enclosingMethod.getReturnType();
@@ -155,7 +155,26 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
'''
}

// GROOVY-10386
// GROOVY-10357
void testAbstractMethodDefault() {
assertScript '''
import java.util.function.Function
abstract class A {
abstract long m(Function<Boolean,Integer> f = { Boolean b -> b ? +1 : -1 })
}
def a = new A() {
@Override
long m(Function<Boolean,Integer> f) {
f(true).longValue()
}
}
assert a.m() == 1L
'''
}

// GROOVY-10358
void testCommonInterface() {
assertScript '''
interface I {
@@ -173,6 +192,7 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
i - 1
}
}
C<String> c = null; int i = 1
int x = (false ? c : new B<String>()).m(i) // Cannot find matching method A#m(int)
assert x == 2

0 comments on commit a80121d

Please sign in to comment.