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 2020/04/26 16:21:30 UTC
[groovy] branch master updated: minor fix-ups
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 55cb5ec minor fix-ups
55cb5ec is described below
commit 55cb5ec2b532412e228c1c5fb01696ba7805972d
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Apr 26 11:20:44 2020 -0500
minor fix-ups
---
.../groovy/classgen/AsmClassGenerator.java | 8 ++---
src/test/gls/innerClass/InnerClassTest.groovy | 34 ++++++++++++----------
2 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 3524267..b6225a0 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -124,6 +124,7 @@ import java.util.Objects;
import java.util.Optional;
import static org.apache.groovy.util.BeanUtils.capitalize;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.thisPropX;
/**
* Generates Java class versions of Groovy classes using ASM.
@@ -1302,9 +1303,9 @@ public class AsmClassGenerator extends ClassGenerator {
private void processClassVariable(final VariableExpression expression) {
if (passingParams && controller.isInScriptBody()) {
- //TODO: check if this part is actually used
+ // TODO: check if this part is actually used
MethodVisitor mv = controller.getMethodVisitor();
- // let's create a ScriptReference to pass into the closure
+ // create a ScriptReference to pass into the closure
mv.visitTypeInsn(NEW, "org/codehaus/groovy/runtime/ScriptReference");
mv.visitInsn(DUP);
@@ -1313,10 +1314,9 @@ public class AsmClassGenerator extends ClassGenerator {
mv.visitMethodInsn(INVOKESPECIAL, "org/codehaus/groovy/runtime/ScriptReference", "<init>", "(Lgroovy/lang/Script;Ljava/lang/String;)V", false);
} else {
- PropertyExpression pexp = new PropertyExpression(new VariableExpression("this"), expression.getName());
+ PropertyExpression pexp = thisPropX(true, expression.getName());
pexp.getObjectExpression().setSourcePosition(expression);
pexp.getProperty().setSourcePosition(expression);
- pexp.setImplicitThis(true);
visitPropertyExpression(pexp);
}
}
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 9f20b7e..6dc5e50 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -19,12 +19,14 @@
package gls.innerClass
import groovy.test.NotYetImplemented
+import groovy.transform.CompileStatic
import org.codehaus.groovy.control.CompilationFailedException
import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
import static groovy.test.GroovyAssert.shouldFail
+@CompileStatic
final class InnerClassTest {
@Test
@@ -633,10 +635,24 @@ final class InnerClassTest {
'''
}
- @Test
+ @Test // GROOVY-4028
void testImplicitThisPassingWithNamedArguments() {
- def oc = new MyOuterClass4028()
- assert oc.foo().propMap.size() == 2
+ assertScript '''
+ class Outer {
+ def inner() {
+ new Inner(fName: 'Roshan', lName: 'Dawrani')
+ }
+ class Inner {
+ Map props
+ Inner(Map props) {
+ this.props = props
+ }
+ }
+ }
+ def outer = new Outer()
+ def inner = outer.inner()
+ assert inner.props.size() == 2
+ '''
}
@Test
@@ -1124,15 +1140,3 @@ class Parent8914 {
class Outer8914 {
static class Nested extends Parent8914.Nested {}
}
-
-class MyOuterClass4028 {
- def foo() {
- new MyInnerClass4028(fName: 'Roshan', lName: 'Dawrani')
- }
- class MyInnerClass4028 {
- Map propMap
- def MyInnerClass4028(Map propMap) {
- this.propMap = propMap
- }
- }
-}