You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by GitBox <gi...@apache.org> on 2019/10/28 18:45:49 UTC
[GitHub] [groovy] eric-milles commented on issue #1048: GROOVY-9292:
Compilation error when accessing a protected(via `thisObject`,
`owner` and `delegate`)/package-private super class field from inside a
closure
eric-milles commented on issue #1048: GROOVY-9292: Compilation error when accessing a protected(via `thisObject`, `owner` and `delegate`)/package-private super class field from inside a closure
URL: https://github.com/apache/groovy/pull/1048#issuecomment-547091592
Here is another take on your change that checks protected and package-private access for the closure's enclosing type.
```java
if (field != null && !field.isPublic()
&& objectExpression instanceof VariableExpression
&& typeCheckingContext.getEnclosingClosure() != null
&& (
(field.isProtected() && typeCheckingContext.getEnclosingClassNode().isDerivedFrom(current))
||
(!field.isPrivate() && Objects.equals(typeCheckingContext.getEnclosingClassNode().getPackageName(), current.getPackageName()))
)
) {
switch (objectExpression.getText()) {
case "it":
case "owner":
case "delegate":
case "thisObject":
objectExpression.putNodeMetaData(StaticCompilationMetadataKeys.RECEIVER_OF_DYNAMIC_PROPERTY, Boolean.TRUE);
}
}
```
I'm still not too keen on dynamic properties. But at least this should stop conversion of forbidden access to missing property. What does not match up is that explicit-this and implicit-this don't produce compiler errors, but instead result in missing property exceptions. I'm just not sure if we know enough to proceed on a change...
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services