[jira] [Commented] (GROOVY-8208) VariableExpressionTransformer does not set source position on property expressions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (GROOVY-8208) VariableExpressionTransformer does not set source position on property expressions

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GROOVY-8208?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16124796#comment-16124796 ]

ASF GitHub Bot commented on GROOVY-8208:
----------------------------------------

GitHub user jwagenleitner opened a pull request:

    https://github.com/apache/groovy/pull/581

    GROOVY-8208: VariableExpressionTransformer does not set source positi…

    …on on property expressions

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jwagenleitner/groovy 8208-varxform

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/581.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #581
   
----
commit 48ce82bce883ee8bcba777a831ad1ee98b70bf45
Author: John Wagenleitner <[hidden email]>
Date:   2017-08-13T04:43:06Z

    GROOVY-8208: VariableExpressionTransformer does not set source position on property expressions

----


> VariableExpressionTransformer does not set source position on property expressions
> ----------------------------------------------------------------------------------
>
>                 Key: GROOVY-8208
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8208
>             Project: Groovy
>          Issue Type: Bug
>          Components: xforms
>            Reporter: Eric Milles
>            Priority: Minor
>
> Two paths in VariableExpressionTransformer create PropertyExpression nodes to stand in for unresolved variable references. Neither case sets the exp source position onto the new node. Other paths through this method transfer position info.
> The fix is simple:
> {code}
> private static Expression tryTransformDelegateToProperty(VariableExpression expr) {
>         // we need to transform variable expressions that go to a delegate
>         // to a property expression, as ACG would loose the information
>         // in processClassVariable before it reaches any makeCall, that could
>         // handle it
>         Object val = expr.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
>         if (val == null) return null;
>         VariableExpression implicitThis = new VariableExpression("this");
>         PropertyExpression pexp = new PropertyExpression(implicitThis, expr.getName());
>         pexp.copyNodeMetaData(expr);
>         pexp.setImplicitThis(true);
>         // GRECLIPSE add
>         pexp.getProperty().setSourcePosition(expr);
>         // GRECLIPSE end
>         ClassNode owner = expr.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
>         if (owner != null) {
>             implicitThis.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, owner);
>             implicitThis.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, val);
>         }
>         return pexp;
>     }
>     private static Expression tryTransformPrivateFieldAccess(VariableExpression expr) {
>         FieldNode field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS);
>         if (field == null) {
>             field = expr.getNodeMetaData(StaticTypesMarker.PV_FIELDS_MUTATION);
>         }
>         if (field != null) {
>             // access to a private field from a section of code that normally doesn't have access to it, like a
>             // closure or an inner class
>             VariableExpression receiver = new VariableExpression("this");
>             PropertyExpression pexp = new PropertyExpression(
>                     receiver,
>                     expr.getName()
>             );
>             pexp.setImplicitThis(true);
>             // GRECLIPSE add
>             pexp.getProperty().setSourcePosition(expr);
>             // GRECLIPSE end
>             // put the receiver inferred type so that the class writer knows that it will have to call a bridge method
>             receiver.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getDeclaringClass());
>             // add inferred type information
>             pexp.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, field.getOriginType());
>             return pexp;
>         }
>         return null;
>     }
> {code}
> The first method affects code like
> {code}
> @groovy.transform.CompileStatic
> class E {
>     D d = new D()
>     void doSomething() {
>         d.with { // 'foo' and 'bar' VariableExpressions are xformed to PropertyExpressions
>             foo = 'foo'
>             bar = new D()
>             bar.foo = 'bar'
>         }
>     }
> }
> {code}
> The second method affects code like
> {code}
> @groovy.transform.CompileStatic
> class X {
>   String id
>   @Lazy Object thing = { ->
>     Directory.lookup(id) // 'id' is transformed from a VariableExpression to a PropertyExpression
>   }()
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)