Skip to content

Commit 86cf6f1

Browse files
committed
GROOVY-7685: Object category method and closure method call
1 parent 2e37575 commit 86cf6f1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/groovy/lang/MetaClassImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@ private Object getMethods(final Class<?> sender, final String name, final boolea
710710
}
711711
for (CategoryMethod cm : methods) {
712712
Class<?> cmdc = cm.getDeclaringClass().getTheClass();
713-
if (cmdc.isAssignableFrom(theClass)) // GROOVY-11813: not sender
713+
if (cmdc == Object.class ? !isGroovyFunctor() // GROOVY-7685
714+
: cmdc.isAssignableFrom(theClass)) // GROOVY-11813
714715
filterMatchingMethodForCategory(array, cm);
715716
}
716717
answer = array;

src/test/groovy/groovy/CategoryTest.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,32 @@ final class CategoryTest {
432432
'''
433433
}
434434

435+
// GROOVY-7685
436+
@Test
437+
void testCategoryMethodAndClosureResolveStrategy() {
438+
assertScript '''
439+
class C {
440+
static m(self) {
441+
'Category'
442+
}
443+
}
444+
class D {
445+
def m() {
446+
'Delegate'
447+
}
448+
}
449+
450+
use(C) {
451+
def x = { ->
452+
assert m() == 'Delegate'
453+
}
454+
x.resolveStrategy = Closure.DELEGATE_ONLY
455+
x.delegate = new D()
456+
x.call()
457+
}
458+
'''
459+
}
460+
435461
// GROOVY-11813
436462
@Test
437463
void testCategoryOperatorMethodAndCustomMetaClass() {

0 commit comments

Comments
 (0)