codeconsole commented on PR #3097:
URL: https://github.com/apache/groovy/pull/3097#issuecomment-6549370768

   @blackdrag I see the conflict. For the same failure, `IllegalAccessError` at 
run time, #3019 reports a compile error and this PR quietly goes dynamic.
   
   What this PR does now:
   
   - **Already in line with #3019.** These cases are rejected at compile time, 
as Java rejects them: `new A(...)` of a protected constructor of another 
package, and a protected method of another package called through a superclass 
receiver.
   - **The part that conflicts.** A protected or package-private member of a 
class that has the same package name but was defined by another 
`GroovyClassLoader` compilation (a class from an earlier `GroovyShell` parse, 
for example). JLS 6.6 counts it as accessible, so #3019's `hasAccessToClass` 
accepts it. The JVM refuses it, so this PR routes the access through the 
meta-class. #3098 does the same for a package-private class from another 
loader, and #3099 for `super.m()`.
   
   The alternative in line with #3019: the type checker treats such a member or 
class as inaccessible and reports "Cannot access ...". This applies to 
`@CompileStatic` and `@TypeChecked`, while dynamic code keeps working. The 
compiler knows the case for certain, because the class comes from a loader 
other than the in-memory compilation's. Code compiled to class files is 
unaffected, as now. Either way it is no regression: today such code compiles 
and then fails with `IllegalAccessError`. The writer changes that route 
accesses through the meta-class (constructors, methods, method-reference 
helpers, fields) would be dropped, which makes the PR much smaller.
   
   If that is what you mean, I'll rework #3097 this way, and #3098 and #3099 
with it. I also merged master in (93d57765fa); `Groovy12484` and this PR's 
tests pass together.
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to