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

Jochen Theodorou commented on GROOVY-9472:
------------------------------------------

[~paulk] I never used the annotation because frankly I have no use for it. But 
if it is that "complicated" to use then (playing a new user's side here) I 
would expect its limitations been documented. That some things don't work with 
joint compilation is a big problem, but this does not work if it is in the same 
compilation Unit and it is not even specific to @CompileStatic. As soon as you 
reference the class in the same CompilationUnit in normal source codeĀ  you get 
a problem. For me this points to that the resolution of classes should not be a 
single pass process if new sources are picked up during resolution, at least 
not if we want to resolve an inner class of that. Of course I am aware of this 
being complicated and introducing complications.

> 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