You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/02/19 19:20:56 UTC
[groovy] branch GROOVY_3_0_X updated (80a57ea -> 3813c31)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.
discard 80a57ea GROOVY-10497: `@NamedVariant`: don't replace explicit value with default
discard 034e50e GROOVY-8448: "this.name" from anon. inner class
new 0f83b23 GROOVY-10497: `@NamedVariant`: don't replace explicit value with default
new 3813c31 GROOVY-8448: "this.name" from anon. inner class
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (80a57ea)
\
N -- N -- N refs/heads/GROOVY_3_0_X (3813c31)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/codehaus/groovy/classgen/AsmClassGenerator.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
[groovy] 02/02: GROOVY-8448: "this.name" from anon. inner class
Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 3813c3155335acd712c93f116a2c9474caaee442
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Feb 19 13:13:21 2022 -0600
GROOVY-8448: "this.name" from anon. inner class
Conflicts:
src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
---
.../org/codehaus/groovy/classgen/AsmClassGenerator.java | 6 ++++++
src/test/gls/innerClass/InnerClassTest.groovy | 15 +++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 22a677e..ae7e188 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -1094,6 +1094,12 @@ public class AsmClassGenerator extends ClassGenerator {
if (expression.isImplicitThis()) fieldNode = classNode.getDeclaredField(name);
} else {
fieldNode = classNode.getDeclaredField(name);
+ // GROOVY-8448: "this.name" from anon. inner class
+ if (fieldNode != null && !expression.isImplicitThis()
+ && (fieldNode.getModifiers() & ACC_SYNTHETIC) != 0
+ && fieldNode.getType().equals(ClassHelper.REFERENCE_TYPE)) {
+ fieldNode = null;
+ }
}
if (fieldNode == null && !isValidFieldNodeForByteCodeAccess(getField(classNode, name), classNode)) {
// GROOVY-9501, GROOVY-9569, GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 618d9d4..98c6e09 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -51,6 +51,21 @@ final class InnerClassTest {
'''
}
+ @Test // GROOVY-8448
+ void testAccessLocalVariableVsGetterInAIC() {
+ assertScript '''
+ def x = 'local' // shared variable written as field in AIC
+ def c = new java.util.concurrent.Callable<String>() {
+ def getX() { 'getter' }
+ @Override String call() {
+ x + ' then ' + this.x
+ }
+ }
+ String result = c()
+ assert result == 'local then getter'
+ '''
+ }
+
@Test
void testAccessLocalVariableFromClosureInAIC() {
assertScript '''
[groovy] 01/02: GROOVY-10497: `@NamedVariant`: don't replace explicit value with default
Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 0f83b23d19b6460db93bf834e3356acc842255d8
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Feb 19 13:11:12 2022 -0600
GROOVY-10497: `@NamedVariant`: don't replace explicit value with default
Conflicts:
src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
---
.../groovy/transform/NamedVariantASTTransformation.java | 8 +++++++-
.../groovy/transform/NamedVariantTransformTest.groovy | 17 ++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
index 28e0cbc..385102c 100644
--- a/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/NamedVariantASTTransformation.java
@@ -71,10 +71,12 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.getAllProperties;
import static org.codehaus.groovy.ast.tools.GeneralUtils.list2args;
import static org.codehaus.groovy.ast.tools.GeneralUtils.mapX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.notNullX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.param;
import static org.codehaus.groovy.ast.tools.GeneralUtils.plusX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.propX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.ternaryX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
@GroovyASTTransformation(phase = CompilePhase.SEMANTIC_ANALYSIS)
@@ -281,7 +283,10 @@ public class NamedVariantASTTransformation extends AbstractASTTransformation {
defaultValue = defaultValueX(type);
}
if (defaultValue != null) {
- value = elvisX(value, defaultValue);
+ if (isPrimitiveType(type)) { // handle null for primitive
+ value = ternaryX(notNullX(value), value, defaultValueX(type));
+ }
+ value = ternaryX(containsKey(mapParam, name), value, defaultValue);
}
return asType(value, type, coerce);
}
@@ -292,6 +297,7 @@ public class NamedVariantASTTransformation extends AbstractASTTransformation {
private static Expression containsKey(final Parameter mapParam, final String name) {
MethodCallExpression call = callX(varX(mapParam), "containsKey", constX(name));
+ call.setImplicitThis(false); // required for use before super ctor call
call.setMethodTarget(MAP_TYPE.getMethods("containsKey").get(0));
return call;
}
diff --git a/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy b/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
index 2ec9135..0c882fd 100644
--- a/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/NamedVariantTransformTest.groovy
@@ -192,7 +192,7 @@ final class NamedVariantTransformTest {
'''
}
- @Test // GROOVY-9158
+ @Test // GROOVY-9158, GROOVY-10497
void testNamedParamWithDefaultArgument() {
assertScript '''
import groovy.transform.*
@@ -226,6 +226,21 @@ final class NamedVariantTransformTest {
m()
}
'''
+
+ assertScript '''
+ import groovy.transform.*
+
+ @NamedVariant
+ def m(int one, int two = 42) {
+ "$one $two"
+ }
+
+ String result = m(one:0, two:0)
+ assert result == '0 0'
+
+ result = m(one:0, two:null)
+ assert result == '0 0'
+ '''
}
@Test // GROOVY-10176