This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch GROOVY-10783 in repository https://gitbox.apache.org/repos/asf/groovy.git
commit e0928d55e019cde354cea955f425ce757d2fb967 Author: Daniel Sun <[email protected]> AuthorDate: Mon Oct 3 05:33:03 2022 +0800 GROOVY-10783: propertyMissing of category does not work when indy enabled Though groovy 4+ enable indy by default, gradle does not. To enable indy in gradle, set `groovyOptions.optimizationOptions.indy = true` --- src/main/java/groovy/lang/MetaClassImpl.java | 3 +++ src/test/groovy/CategoryTest.groovy | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/groovy/lang/MetaClassImpl.java b/src/main/java/groovy/lang/MetaClassImpl.java index 7617f376f3..2c0c40ac90 100644 --- a/src/main/java/groovy/lang/MetaClassImpl.java +++ b/src/main/java/groovy/lang/MetaClassImpl.java @@ -2118,6 +2118,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass { //---------------------------------------------------------------------- if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) { method = getCategoryMethodGetter(sender, "get", true); + if (null == method) { + method = getCategoryMethodGetter(sender, PROPERTY_MISSING, true); + } if (method != null) { return new GetMethodMetaProperty(name, VM_PLUGIN.transformMetaMethod(this, method)); } diff --git a/src/test/groovy/CategoryTest.groovy b/src/test/groovy/CategoryTest.groovy index f8c0a0f2a7..7f0c2e662b 100644 --- a/src/test/groovy/CategoryTest.groovy +++ b/src/test/groovy/CategoryTest.groovy @@ -21,7 +21,6 @@ package groovy import groovy.test.GroovyTestCase import static groovy.test.GroovyAssert.isAtLeastJdk -import static org.junit.Assume.assumeTrue final class CategoryTest extends GroovyTestCase { @@ -358,6 +357,20 @@ final class CategoryTest extends GroovyTestCase { } } + // GROOVY-10783 + void testPropertyMissing2() { + assertScript '''\ + class X{ def bar(){1}} + class XCat4{ static propertyMissing(X x, String name) {"works"}} + + def x = new X() + + use(XCat4) { + assert x.baz == "works" + } + ''' + } + // GROOVY-3867 void testMethodMissing() { def x = new X()
