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 A0F9B200D49 for ; Fri, 24 Nov 2017 10:16:39 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9F627160BF2; Fri, 24 Nov 2017 09:16:39 +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 E2AFE160BEE for ; Fri, 24 Nov 2017 10:16:38 +0100 (CET) Received: (qmail 83841 invoked by uid 500); 24 Nov 2017 09:16:38 -0000 Mailing-List: contact dev-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 dev@groovy.apache.org Received: (qmail 83831 invoked by uid 99); 24 Nov 2017 09:16:37 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Nov 2017 09:16:37 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 0C39F1A0E6A for ; Fri, 24 Nov 2017 09:16:37 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.001 X-Spam-Level: X-Spam-Status: No, score=-3.001 tagged_above=-999 required=6.31 tests=[RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-2.8, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 44a4fi9shgFZ for ; Fri, 24 Nov 2017 09:16:35 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 6756C60CF8 for ; Fri, 24 Nov 2017 09:16:34 +0000 (UTC) Received: from [192.168.1.5] ([77.176.100.129]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LeSOH-1ewRS83KIf-00qDqd for ; Fri, 24 Nov 2017 10:16:33 +0100 Subject: Re: Is FieldsAndPropertiesStaticCompileTest#testUseGetterFieldAccess really correct? To: dev@groovy.apache.org References: From: Jochen Theodorou Message-ID: <510cf0eb-8d97-d3f4-d46f-e4771f570656@gmx.org> Date: Fri, 24 Nov 2017 10:16:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:zQhKeFK9THb/twHc5S4+KmCilk+ehbEqSy4krFHivqXRkhTvDnB h3YwMmm9aZ+PlQdC6UVLdUdfCNapjt7vqH6WDKw1VddrukimtMNE3njZ4XyTIw+gmjN9NBI 1RI7zYEuM21GYvnLC+/8I8i/uYHlE39/62cuLx+alPs4rkxLYji7JVO/+UpX/TauRKOKgef h3kBfbcoMWoBHlBg8+72g== X-UI-Out-Filterresults: notjunk:1;V01:K0:D944lh4HY7U=:BBiDCTrvBbUZy7NGhJq6oA Qj/BKSaxUVje60yffp1wdTk33JH+42sv5CZERdVdeLL7LjK7H6kAADqEDYjrIOxuqC/eBrWx3 vjRXRaM0OqoUGgu2mgrU9F2qy/sqz6wBY2VrERxfnSmaFC2kBequXNYB8JQgk9CXsx3zb/9SZ rWphDPL3Ryef3FgR5YFtUskwjOOKnACXBskr6HALD9ycj8V77VxeuGr7RIP9TpCTt2LSqJaIW 60L1X0E53hoifO4cuDZLI+2d/BEdWKylkaaIcrZlgszHtyA+Awsn/GRxH/cla/CIudOuJQ9Z4 mLFUJwRBHpyWnBhmtxXzJvlXorBmtpa4femgFSJLLXHgOcY+IPfTYGj4q1f5zul3eUgutdQPr cZXv+v9Z/EAJPggwKfaBg4A/n+sg9cICsRQtpITE15VQ6q7sRXkuhkVPXi2jBz3uMZKVF0sg5 XuhlKSP0+iW3TDEqa1RbSKGpzUHMxRXc99d43WbDXPUgAQ7/0lTX5LqupJ0KFPkupGTTak0we kb78s0XDuzHkZznyvRv6yBeN2Lw+5uke/SXPYMlgCAWKBbSsTOtuhuy5BkkVyqTOKueFYN+M7 /tElHjMcFUonBZznTMt1bn3CjSP/CQOGvOImAxvqjJ1Bsa6qyzYH0mSFiTJ1GSZgxJ0REMYZu ZcAqsaOazHaICWB20LpBlce+vdaf2CKbLDadgg/9FEr3laBJokyqsvRhOmhD/HQCqScPXk2o7 2Us74pYoS2gePHT31bjTXWAaKtPdJvW5ATzUvUG6hkG/iP4x2UbqaEYMl7DUeYHsUlSpP7Vna mMo+EZ6ze2LFsuOoKM9R11ZDGDbvviO7x3g/p7blSpnja0TtlQ= archived-at: Fri, 24 Nov 2017 09:16:39 -0000 Am 24.11.2017 um 09:09 schrieb Mauro Molinari: > Il 24/11/2017 01:46, Jochen Theodorou ha scritto: >> In my opinion the test is wrong, but I'd like to hear others about this. >> >> And another point. We seem to have no similar test for dynamic Groovy. >> Groovy does use direct field access if the field is available on >> "this". But the question here is if that extends to all super classes. >> In my opinion it should. >> >> If I get no vetos I will push a fix for this for all current groovy >> versions > > I don't know if I understood it right, but are you saying that you think > that invoking b.usingGetter() in your example should not call A.getX(), > but rather access A.x directly? And that, I guess, the same policy > should apply for the corresponding setter? yes, just that we do not have a test for this. > I guess you think so because A.x is declared as protected, don't you? > Because if A.x had no modifier, I think that such a change may break a > lot of code that assumes getter/setter are called, in particular I'm > thinking of the write access case for @Bindable fields I am thinking so because in > class X { > def x > def foo(){x} > } we will access the field directly. It will access the field directly, because the field is accessible. In > class X { > def x > } > class Y extends X { > def foo(){x} > } the field itself is not accessible and the getter/setter must be used. But in > class X { > public x > def getX(){x} > } > class Y extends X { > def foo(){x} > } the field is accessible, thus I think the access should be done directly. And then there is the following to consider as well: > class X { > public x > def getX(){x} > } > class Y extends X { > def foo(){super.x} > } This will access the field directly in todays implementation. And this here > ​ class X { > public x=1 > def getX(){x+10} > } > class Y extends X {} > class Z extends Y { > def foo(){super.x} > } will not access the field directly in todays implementation. And if the field is private or does not exist even super.x would always use the getter, as would this.x I think the rules should be the following: this.x and super.x should access the field if the field is accessible. If the field is not accessible, then x has to be accessed as property (which would prefer the getter/setter over the field) Accessible here means for me first and for all, if the field is defined in the same class, then for this.x the field is always accessible, regardless of any modifier. If the field is from a super class, the field must be public or protected. Inaccessible fields are to be ignored. Example: > ​ class X { > public x > def getX(){x} > } > class Y extends X { > private x > } > class Z extends Y { > def foo(){super.x} > } should also access the field in X, same for this.x instead of super.x The current implementation feels inconsistent to me. Will this break code? that may very well be. But I think the chance is not that big. And then finally there is the question of if we do not want this, do we want it different for @CompileStatic? bye Jochen