Skip to content

Commit 2a7d1e9

Browse files
committed
minor refactor: remove deprecated method usage
1 parent 5b62bf5 commit 2a7d1e9

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/main/java/org/codehaus/groovy/runtime/metaclass/ClosureMetaClass.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ private static class NormalMethodChooser implements MethodChooser {
145145
public Object chooseMethod(final Class<?>[] arguments, final boolean coerce) {
146146
if (arguments.length == 0) {
147147
return MetaClassHelper.chooseEmptyMethodParams(methods);
148-
} else if (arguments.length == 1 && arguments[0] == null) {
149-
return MetaClassHelper.chooseMostGeneralMethodWith1NullParam(methods);
150148
} else {
151149
int methodCount = methods.size();
152150
List<Object> matchingMethods = new ArrayList<>(methodCount);

src/test/groovy/gls/invocation/MethodSelectionTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,33 @@ final class MethodSelectionTest extends CompilableTestSupport {
102102
'''
103103
}
104104

105+
@Test // GROOVY-6289: closure doCall with null selects most specific applicable method
106+
void testClosureCallWithNullSelectsMethod() {
107+
assertScript '''
108+
class MyClosure extends Closure {
109+
MyClosure(owner) { super(owner) }
110+
def doCall(String s) { 'string' }
111+
def doCall(Integer i) { 'integer' }
112+
}
113+
// String is more specific than Integer for null (both reference types)
114+
assert new MyClosure(this)(null) == 'string'
115+
'''
116+
}
117+
118+
@Test // GROOVY-6289: closure doCall with null and unrelated types should be ambiguous
119+
void testClosureCallWithNullAmbiguous() {
120+
shouldFail '''
121+
class A {}
122+
class B {}
123+
class MyClosure extends Closure {
124+
MyClosure(owner) { super(owner) }
125+
def doCall(A a) { 'a' }
126+
def doCall(B b) { 'b' }
127+
}
128+
new MyClosure(this)(null)
129+
'''
130+
}
131+
105132
@Test
106133
void testMethodSelectionException() {
107134
assertScript '''

0 commit comments

Comments
 (0)