[
https://issues.apache.org/jira/browse/GROOVY-5942?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-5942.
-----------------------------
> CompileStatic error changes when portions of app moved from groovy to java or
> order of compilation changed
> ----------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-5942
> URL: https://issues.apache.org/jira/browse/GROOVY-5942
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 2.0.6
> Reporter: Andy Clement
> Priority: Major
>
> These 3 files:
> {code}Top.groovy
> package q;
> public class Top {
> protected String m = "xyz";
> }
> {code}
> {code}Bottom.groovy
> package q;
> class Bottom extends Top {}
> {code}
> {code}Simple.groovy
> package p;
> @groovy.transform.CompileStatic
> public class Simple {
> public static void main(String[] argv) {
> print new Bottom().m;
> }
> {code}
> compile all with groovyc, returns:
> {code}
> groovyc Simple.groovy Top.groovy Bottom.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> Simple.groovy: 7: Access to q.Bottom#m is forbidden @ line 7, column 11.
> print new Bottom().m;
> ^
> 1 error
> {code}
> If we change Top.groovy > Top.java, it will compile clean:
> {code}
> groovyc -j Simple.groovy Top.java Bottom.groovy
> {code}
> If we kept the all groovy version and change the order, it will also compile
> clean:
> {code}
> groovyc Top.groovy Bottom.groovy Simple.groovy
> {code}
> I believe it is due to a combination of two things.
> When the code generation step runs, whether the error comes out depends on
> whether Bottom has been tagged with "GroovyObject", which the call to the
> verifier adds.
> When compiling them in the mixed case, stub generation forces the verifier to
> run on Bottom, it gets GroovyObject and then things compile clean.
> When compiling all as groovy, if Simple is built first then Bottom does not
> have GroovyObject (error comes out), if Simple is built last, Bottom does
> have GroovyObject (errors does not come out).
> In Groovy-Eclipse I improved the situation by pulling the call to the
> verifier out of the classgen step in CompilationUnit and running it as an
> earlier verify step. This ensures all files get verified (and GroovyObject
> added) before the AsmClassGenerator runs (which is what produces the message).
> On top of that I think the error should probably be coming out in all cases
> (unless groovy allows breaking these vis rules, I'm not sure on that) but the
> check doesn't seem quite right:
> In StaticTypesCallSiteWriter
> {code}
> private static boolean isDirectAccessAllowed(FieldNode a, ClassNode
> receiver, boolean isSamePackage) {
>
> ....
> ....
> // no getter
> return a.isPublic() || (a.isProtected() && isSamePackage);
> }
> {code}
> protected doesn't mean you can access it if in the same package, which I
> think is what that condition check implies. Default visibility means same
> package. protected means class hierarchy visibility.
> There is a piece of grails-core that currently compiles cleanly because of
> this situation. If the error were to be switched on for all variants,
> grails-core will need refactoring.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)