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/05/13 13:50:58 UTC
[groovy] branch danielsun/lab-indy-20220512 updated: Avoid unnecessary guards for receiver and parameter of "childless" type
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch danielsun/lab-indy-20220512
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/danielsun/lab-indy-20220512 by this push:
new 32564f7c05 Avoid unnecessary guards for receiver and parameter of "childless" type
32564f7c05 is described below
commit 32564f7c05e4e602571b143758a7ad337544be96
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri May 13 21:50:27 2022 +0800
Avoid unnecessary guards for receiver and parameter of "childless" type
---
.../java/org/codehaus/groovy/vmplugin/v8/Selector.java | 7 ++++++-
src/test/indy/IndyUsageTest.groovy | 15 ++++++++++++++-
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java
index 713810f68a..69e889b618 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java
@@ -63,6 +63,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -933,7 +934,11 @@ public abstract class Selector {
if (LOG_ENABLED) LOG.info("added null argument check at pos " + i);
} else {
if (Modifier.isFinal(paramType.getModifiers())) {
- // primitive types are also `final`
+ // e.g. `final` types, e.g. `String`, primitive types, `enum` types
+ continue;
+ }
+ if (Arrays.stream(paramType.getDeclaredConstructors()).allMatch(c -> Modifier.isPrivate(c.getModifiers()))) {
+ // e.g. singleton
continue;
}
test = SAME_CLASS.
diff --git a/src/test/indy/IndyUsageTest.groovy b/src/test/indy/IndyUsageTest.groovy
index 5e95ca7724..f720d3b7bf 100644
--- a/src/test/indy/IndyUsageTest.groovy
+++ b/src/test/indy/IndyUsageTest.groovy
@@ -23,7 +23,6 @@ import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
final class IndyUsageTest {
-
@Test
void testIndyIsUsedNested() {
assertScript '''
@@ -37,4 +36,18 @@ final class IndyUsageTest {
}
'''
}
+
+ @Test
+ void testMethodWithSingletonParamType() {
+ assertScript '''
+ class Singleton {
+ private Singleton() {}
+ public static final Singleton INSTANCE = new Singleton()
+ }
+ def foo(Singleton p) {
+ return p
+ }
+ assert Singleton.INSTANCE === foo(Singleton.INSTANCE)
+ '''
+ }
}