Fwd: groovy git commit: GROOVY-5912: Static compilation: Groovy doesn't fail compilation when accessing package scope methods, but fails at runtime

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

Fwd: groovy git commit: GROOVY-5912: Static compilation: Groovy doesn't fail compilation when accessing package scope methods, but fails at runtime

jwagenleitner
Just a question, I thought that @TypeChecked is designed to work similar to dynamic mode as far as method dispatch and access (i.e., private/protected ok). If filtering methods by visibility is done in the `StaticTypeCheckingVisitor` wouldn't change that behavior. Is that something expected for 2.5?

P.S. Also seems the following line should include a "same package" check as well

if (methodNode.isProtected() && !enclosingClassNode.isDerivedFrom(declaringClass)) {
    continue;
}

---------- Forwarded message ---------
From: <[hidden email]>
Date: Tue, May 15, 2018 at 8:44 AM
Subject: groovy git commit: GROOVY-5912: Static compilation: Groovy doesn't fail compilation when accessing package scope methods, but fails at runtime
To: <[hidden email]>


Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X d1970bcf6 -> 7804d4ea9


GROOVY-5912: Static compilation: Groovy doesn't fail compilation when accessing package scope methods, but fails at runtime

(cherry picked from commit b1cc8a6)

[.....]

+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4415,6 +4415,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             if (methodNode.isProtected() && !enclosingClassNode.isDerivedFrom(declaringClass)) {
                 continue;
             }
+            if (methodNode.isPackageScope() && !getPackageName(enclosingClassNode).equals(getPackageName(declaringClass))) {
+                continue;
+            }

             result.add(methodNode);
         }
@@ -4422,6 +4425,12 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         return result;
     }

[.....]