You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2015/10/07 21:16:55 UTC
[2/5] incubator-groovy git commit: GROOVY-7597 Static compiler tries
to cast delegate to target type of property accessor * Remove setting of
INFERRED_TYPE metadata on synthetic property expression for implicit receiver
GROOVY-7597 Static compiler tries to cast delegate to target type of property accessor
* Remove setting of INFERRED_TYPE metadata on synthetic property expression for implicit receiver
Closes #126
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/8a5cd2d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/8a5cd2d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/8a5cd2d2
Branch: refs/heads/master
Commit: 8a5cd2d24fb842c64a9a4c9d6b7310af6876b8ff
Parents: 0a54e55
Author: Shil S <sh...@gmail.com>
Authored: Sun Oct 4 15:11:40 2015 -0400
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed Oct 7 21:09:40 2015 +0200
----------------------------------------------------------------------
.../classgen/asm/sc/StaticInvocationWriter.java | 4 ---
.../asm/sc/DelegatesToStaticCompileTest.groovy | 33 ++++++++++++++++++++
2 files changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/8a5cd2d2/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index be657ac..12cca0e 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -562,7 +562,6 @@ public class StaticInvocationWriter extends InvocationWriter {
boolean tryImplicitReceiver(final Expression origin, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean safe, final boolean spreadSafe, final boolean implicitThis) {
Object implicitReceiver = origin.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
- ClassNode propertyOwnerType = origin.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
if (implicitThis && implicitReceiver==null && origin instanceof MethodCallExpression) {
implicitReceiver = ((MethodCallExpression) origin).getObjectExpression().getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
}
@@ -576,9 +575,6 @@ public class StaticInvocationWriter extends InvocationWriter {
pexp = new PropertyExpression(pexp, propertyPath[i]);
}
pexp.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, implicitReceiver);
- if (propertyOwnerType!=null) {
- pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, propertyOwnerType);
- }
origin.removeNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
if (origin instanceof PropertyExpression) {
PropertyExpression rewritten = new PropertyExpression(
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/8a5cd2d2/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
index da7a690..e4b2cb2 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/DelegatesToStaticCompileTest.groovy
@@ -80,4 +80,37 @@ class DelegatesToStaticCompileTest extends DelegatesToSTCTest implements StaticC
assert bytecode.contains('INVOKEVIRTUAL org/codehaus/groovy/classgen/asm/sc/Groovy6955Support$Request.getHeaders')
}
}
+
+ // GROOVY-7597
+ void testImplicitDelegateShouldNotBeCheckedAsTypeOfPropertyOwner() {
+ try {
+ assertScript '''
+ class Calculation {
+ boolean isValid() { true }
+ }
+
+ class Entity {
+ Calculation getCalculation(String name) { new Calculation() }
+ }
+
+ class Handler {
+ def doWithEntity(@DelegatesTo(Entity) Closure c) {
+ new Entity().with(c)
+ }
+
+ def doIt() {
+ doWithEntity() {
+ getCalculation("whatever").valid
+ }
+ }
+ }
+
+ assert new Handler().doIt()
+ '''
+ } finally {
+ def bytecode = astTrees['Handler$_doIt_closure1'][1]
+ assert !bytecode.contains('CHECKCAST Calculation')
+ assert !bytecode.contains('INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType')
+ }
+ }
}
\ No newline at end of file