[ 
https://issues.apache.org/jira/browse/GROOVY-9472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508139#comment-17508139
 ] 

Daniil Ovchinnikov commented on GROOVY-9472:
--------------------------------------------

[~emilles] 

> If you include the class or classes that file1 generates on the classpath 
> when compiling file2 there can be a significant difference

Yes, this difference is the problem. 

[~blackdrag] 

> If some units completed and added new classes or sources to the AST, then 
> repeat.

Repeat re-trying to resolve references which were not resolved previously, i.e. 
if a reference got resolved, then it stays resolved.

I'd expect the resolution to work like this:
 # Resolve resolvable member types/annotations
 # Run transformations 
 # Resolve unresolved references in members
 # Resolve the references in bodies (both AST and generated, both types and 
variables/methods/fields)

The output of the second step is fixed after its completion, no more members 
are guaranteed to appear. The output of the third step is enough to do any 
static analysis in {{@CompileStatic}} mode, and it is enough to generate the 
stubs for the joint compilation. This approach aligns well with what IDEs do, 
and what other compilers do.

I'd also split transformation run into two separate steps: instead of 2, run 
transformations to determine the set of members and types, then generate method 
bodies between 3 and 4.

> Static import causes unresolved reference to become resolved
> ------------------------------------------------------------
>
>                 Key: GROOVY-9472
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9472
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Static Type Checker
>    Affects Versions: 2.5.10
>            Reporter: Daniil Ovchinnikov
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0
>
>
> {code:groovy|title=com/foo/Person.groovy}
> package com.foo
> @groovy.transform.builder.Builder
> class Person {
>     String name
> }
> {code}
> 1.
> {code:groovy|title=Main.groovy}
> import com.foo.Person
> class Main {
>     static void main(String[] args) {
>         Person.PersonBuilder pb = Person.builder() 
>         println(pb.build())
>     }
> }
> {code}
> Trying to use it without a static import yields {{unable to resolve class 
> Person.PersonBuilder}}, which is another issue.
> 2. Let's add a static import
> {code:groovy|title=Main.groovy}
> import com.foo.Person
> import static com.foo.Person.PersonBuilder
> class Main {
>     static void main(String[] args) {
>         PersonBuilder pb = Person.builder()
>         println(pb.build())
>     }
> }
> {code}
> The code compiles, but fails with {{java.lang.NoClassDefFoundError: 
> PersonBuilder}} when run.
> 3. Let's add {{@CompileStatic}}
> {code:groovy|title=Main.groovy}
> import com.foo.Person
> import static com.foo.Person.PersonBuilder
> import groovy.transform.CompileStatic
> @CompileStatic
> class Main {
>     static void main(String[] args) {
>         PersonBuilder pb = Person.builder()
>         println(pb.build())
>     }
> }
> {code}
> Compilation fails with: 
>  {{Cannot assign value of type com.foo.Person$PersonBuilder to variable of 
> type PersonBuilder}} and {{Cannot find matching method PersonBuilder#build()}}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to