You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/05/06 14:59:27 UTC
[groovy] 01/03: GROOVY-9007: Getting java.lang.NoSuchFieldError
with groovy version 2.5.6
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 13ba4e6c614e33020774589587f7f890850d9f1c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed May 1 11:46:31 2019 +1000
GROOVY-9007: Getting java.lang.NoSuchFieldError with groovy version 2.5.6
---
.../transform/stc/StaticTypeCheckingVisitor.java | 31 +++++++++++-----------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index b0de69b..8b12515 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -527,23 +527,22 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
/**
- * Given a field node, checks if we are accessing or setting a public or protected field from an inner class.
+ * Checks valid cases for accessing a field from an inner class.
*/
- private String checkOrMarkInnerFieldAccess(Expression source, FieldNode fn, boolean lhsOfAssignment, String delegationData) {
- if (fn == null || fn.isStatic()) return delegationData;
- ClassNode enclosingClassNode = typeCheckingContext.getEnclosingClassNode();
- ClassNode declaringClass = fn.getDeclaringClass();
- // private handled elsewhere
- if ((fn.isPublic() || fn.isProtected()) &&
- (declaringClass != enclosingClassNode || typeCheckingContext.getEnclosingClosure() != null) &&
- declaringClass.getModule() == enclosingClassNode.getModule() && !lhsOfAssignment && enclosingClassNode.isDerivedFrom(declaringClass)) {
- if (source instanceof PropertyExpression) {
- PropertyExpression pe = (PropertyExpression) source;
- // this and attributes handled elsewhere
- if ("this".equals(pe.getPropertyAsString()) || source instanceof AttributeExpression) return delegationData;
- pe.getObjectExpression().putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, "owner");
+ private String checkOrMarkInnerPropertyOwnerAccess(Expression source, FieldNode fn, boolean lhsOfAssignment, String delegationData) {
+ if (fn == null || fn.isStatic() || fn.isPrivate() || "delegate".equals(delegationData)) return delegationData;
+ if (source instanceof PropertyExpression && typeCheckingContext.getEnclosingClosure() != null) {
+ PropertyExpression pe = (PropertyExpression) source;
+ boolean ownerProperty = !("this".equals(pe.getPropertyAsString()));
+ if (ownerProperty && pe.getObjectExpression() instanceof VariableExpression) {
+ Variable accessedVariable = ((VariableExpression) pe.getObjectExpression()).getAccessedVariable();
+ Variable declaredVariable = typeCheckingContext.getEnclosingClosure().getClosureExpression().getVariableScope().getDeclaredVariable(pe.getObjectExpression().getText());
+ if (accessedVariable != null && accessedVariable == declaredVariable) ownerProperty = false;
+ }
+ if (ownerProperty) {
+ delegationData = "owner";
+ pe.getObjectExpression().putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData);
}
- return "owner";
}
return delegationData;
}
@@ -1846,7 +1845,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (visitor != null) visitor.visitField(field);
storeWithResolve(field.getOriginType(), receiver, field.getDeclaringClass(), field.isStatic(), expressionToStoreOn);
checkOrMarkPrivateAccess(expressionToStoreOn, field, lhsOfAssignment);
- delegationData = checkOrMarkInnerFieldAccess(expressionToStoreOn, field, lhsOfAssignment, delegationData);
+ delegationData = checkOrMarkInnerPropertyOwnerAccess(expressionToStoreOn, field, lhsOfAssignment, delegationData);
if (delegationData != null) {
expressionToStoreOn.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData);
}