You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/10/05 17:51:19 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10783: propertyMissing of category does not work when indy enabled
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 42a1443776 GROOVY-10783: propertyMissing of category does not work when indy enabled
42a1443776 is described below
commit 42a1443776ba4c189ddc0d6202c5461e903ffb7b
Author: Daniel Sun <su...@apache.org>
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`
(cherry picked from commit eafa345aaf142a1358f9884214d3523e3f7fff35)
---
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 5eb722a513..11b92ac13b 100644
--- a/src/main/java/groovy/lang/MetaClassImpl.java
+++ b/src/main/java/groovy/lang/MetaClassImpl.java
@@ -2113,6 +2113,9 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
// check for a generic get method provided through a category
if (!useSuper && !isStatic && GroovyCategorySupport.hasCategoryInCurrentThread()) {
method = getCategoryMethodGetter(sender, "get", true);
+ if (null == method) {
+ method = getCategoryMethodGetter(sender, PROPERTY_MISSING, true);
+ }
if (method != null) {
MetaMethod transformedMetaMethod = VM_PLUGIN.transformMetaMethod(this, method);
return new GetMethodMetaProperty(name, transformedMetaMethod);
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()