[ 
https://issues.apache.org/jira/browse/GROOVY-7932?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Cazacu Mihai updated GROOVY-7932:
---------------------------------
    Description: 
{code:title=Test.groovy|borderStyle=solid}
import groovy.transform.CompileStatic

@CompileStatic
interface Handler<E> {
    void handle(E event)
}

@CompileStatic
class Person {

    final String name

    // marking this method as 'protected' will fix the issue
    private Person(String name) {
        this.name = name
    }

    static void load(String name, Handler<Person> handler) {
        Thread.start {
            Person person = new Person(name)
            handler.handle(person)
        }
    }

}

Person.load('John') { Person p ->
    println p.name
}

{code}

Error:

{quote}
Test.groovy: 20: Cannot call private constructor for Person from class 
Person$_load_closure1 @ line 20, column 20.
                        Person person = new Person(name)
                      ^

1 error
{quote}

  was:
{code:title=Test.groovy|borderStyle=solid}
import groovy.transform.CompileStatic

@CompileStatic
interface Handler<E> {
        void handle(E event)
}

@CompileStatic
class Person {

        final String name

        // marking this method as 'protected' will fix the issue
        private Person(String name) {
                this.name = name
        }

        static void load(String name, Handler<Person> handler) {
                Thread.start {
                        Person person = new Person(name)
                        handler.handle(person)
                }
        }

}

Person.load('John') { Person p ->
        println p.name
}
{code}

Error:

{quote}
Test.groovy: 20: Cannot call private constructor for Person from class 
Person$_load_closure1 @ line 20, column 20.
                        Person person = new Person(name)
                      ^

1 error
{quote}


> Cannot call private constructor from clojures
> ---------------------------------------------
>
>                 Key: GROOVY-7932
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7932
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.7, 2.5.x
>         Environment: Ubuntu 16.04
> openjdk version "1.8.0_91"
>            Reporter: Cazacu Mihai
>
> {code:title=Test.groovy|borderStyle=solid}
> import groovy.transform.CompileStatic
> @CompileStatic
> interface Handler<E> {
>     void handle(E event)
> }
> @CompileStatic
> class Person {
>     final String name
>     // marking this method as 'protected' will fix the issue
>     private Person(String name) {
>         this.name = name
>     }
>     static void load(String name, Handler<Person> handler) {
>         Thread.start {
>             Person person = new Person(name)
>             handler.handle(person)
>         }
>     }
> }
> Person.load('John') { Person p ->
>     println p.name
> }
> {code}
> Error:
> {quote}
> Test.groovy: 20: Cannot call private constructor for Person from class 
> Person$_load_closure1 @ line 20, column 20.
>                       Person person = new Person(name)
>                       ^
> 1 error
> {quote}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to