Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8CBF7200C63 for ; Thu, 11 May 2017 08:33:54 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8B72C160BCA; Thu, 11 May 2017 06:33:54 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DA61B160BB2 for ; Thu, 11 May 2017 08:33:53 +0200 (CEST) Received: (qmail 8054 invoked by uid 500); 11 May 2017 06:33:53 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 8043 invoked by uid 99); 11 May 2017 06:33:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 May 2017 06:33:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DE4F3DFDD5; Thu, 11 May 2017 06:33:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: shils@apache.org To: commits@groovy.apache.org Date: Thu, 11 May 2017 06:33:53 -0000 Message-Id: In-Reply-To: <85cfd57411ab4fccb6470af5ff62c477@git.apache.org> References: <85cfd57411ab4fccb6470af5ff62c477@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] groovy git commit: GROOVY-8074: Statically compiled dot property accesses instance property instead of Map property (closes #539) archived-at: Thu, 11 May 2017 06:33:54 -0000 GROOVY-8074: Statically compiled dot property accesses instance property instead of Map property (closes #539) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/946eadb9 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/946eadb9 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/946eadb9 Branch: refs/heads/GROOVY_2_5_X Commit: 946eadb9c4115daca3a382816f3aa42a4a1c7005 Parents: 8bd2e44 Author: Shil Sinha Authored: Sun May 7 14:47:19 2017 -0400 Committer: Shil Sinha Committed: Thu May 11 02:26:09 2017 -0400 ---------------------------------------------------------------------- .../asm/sc/StaticTypesCallSiteWriter.java | 26 +++++++++----------- ...ArraysAndCollectionsStaticCompileTest.groovy | 12 +++++++++ 2 files changed, 24 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/946eadb9/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java index 727739d..02203ad 100644 --- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java +++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java @@ -137,6 +137,15 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes expr.visit(controller.getAcg()); return; } + + boolean isStaticProperty = receiver instanceof ClassExpression + && (receiverType.isDerivedFrom(receiver.getType()) || receiverType.implementsInterface(receiver.getType())); + + if (!isStaticProperty && (receiverType.implementsInterface(MAP_TYPE) || MAP_TYPE.equals(receiverType))) { + // for maps, replace map.foo with map.get('foo') + writeMapDotProperty(receiver, methodName, mv, safe); + return; + } if (makeGetPropertyWithGetter(receiver, receiverType, methodName, safe, implicitThis)) return; if (makeGetField(receiver, receiverType, methodName, safe, implicitThis, samePackages(receiverType.getPackageName(), classNode.getPackageName()))) return; if (receiverType.isEnum()) { @@ -211,22 +220,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes } } - boolean isStaticProperty = receiver instanceof ClassExpression - && (receiverType.isDerivedFrom(receiver.getType()) || receiverType.implementsInterface(receiver.getType())); - - if (!isStaticProperty) { - if (receiverType.implementsInterface(MAP_TYPE) || MAP_TYPE.equals(receiverType)) { - // for maps, replace map.foo with map.get('foo') - writeMapDotProperty(receiver, methodName, mv, safe); - return; - } - if (receiverType.implementsInterface(LIST_TYPE) || LIST_TYPE.equals(receiverType)) { - writeListDotProperty(receiver, methodName, mv, safe); - return; - } + if (!isStaticProperty && (receiverType.implementsInterface(LIST_TYPE) || LIST_TYPE.equals(receiverType))) { + writeListDotProperty(receiver, methodName, mv, safe); + return; } - controller.getSourceUnit().addError( new SyntaxException("Access to "+ (receiver instanceof ClassExpression ?receiver.getType():receiverType).toString(false) http://git-wip-us.apache.org/repos/asf/groovy/blob/946eadb9/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy index fbb4f3c..3e6f278 100644 --- a/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy +++ b/src/test/org/codehaus/groovy/classgen/asm/sc/ArraysAndCollectionsStaticCompileTest.groovy @@ -128,6 +128,18 @@ class ArraysAndCollectionsStaticCompileTest extends ArraysAndCollectionsSTCTest } } + void testMapSubclassPropertyStyleAccess() { + assertScript ''' + class MyMap extends LinkedHashMap { + def foo = 1 + } + + def map = new MyMap() + map.put('foo', 42) + assert map.foo == 42 + ''' + } + @Override void testForInLoop() { try {