jdaugherty commented on PR #3084:
URL: https://github.com/apache/groovy/pull/3084#issuecomment-6511397772

   Thanks for the review.
   
   **Compatibility.** Added to the PR description and to the JIRA. For a 
compilation unit in the default package, a simple type name that is not 
declared or imported in the unit and not in the same `CompilationUnit` is now 
looked up on the class path, and on the source path of the `GroovyClassLoader`, 
as a default-package class before the default imports. A default-package `List` 
or `Node` on the class path therefore shadows `java.util.List` / 
`groovy.util.Node` in default-package code, where the default import used to 
win. That matches Java (JLS ยง6.4.1: a type declared in the same package, the 
unnamed package included, shadows a type imported on demand), what Groovy 
already does when the class is in the same `CompilationUnit`, and what 
`resolveFromModule` already does for a named package via 
`ConstructedClassWithPackage(module.getPackageName(), name)`. The named-package 
path also means the extra lookup is nothing new: a named-package unit already 
pays one cached class-path miss per
  JDK simple name (`foo.String`); a default-package unit now pays the same.
   
   **Side effects of `resolveToOuter`.** A miss leaves the `ClassNode` 
untouched; `setRedirect` is only called on a hit. The only state change is that 
`ClassNodeResolver.resolveName` caches the name as `NO_CLASS` in the resolver 
shared by the `CompilationUnit`. The later `resolveToOuter(type)` in the chain 
is only reached when the default imports also miss, and it then returns `null` 
from the cache, so it is a no-op. On a hit the `||` chain short-circuits and 
the later call never runs. The source-unit case (`Interrupt`, restart) is the 
same path the later call would have taken, only earlier. I added a one-line 
note to the Javadoc of `resolveFromDefaultPackage`, and moved the method above 
the Javadoc of `resolveToOuter`, which the first version had separated from its 
method. The backport branch has the same Javadoc.
   


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