Re: Static type checking

2016-09-02 Thread Mihai Cazacu
Done: GROOVY-7927 .


Re: Static type checking

2016-09-02 Thread Cédric Champeau
This is clearly a bug. Can you file a JIRA issue for this?

2016-09-02 15:05 GMT+02:00 cazacugmihai :

> Hi,
>
> I have a problem running this code:
>
> import groovy.transform.CompileStatic
> import java.util.function.Function
>
> @CompileStatic
> class Test {
> static void main(String[] args) {
>// this code fails
> Function fct = { Integer n ->
> -n
> }
>
> // this one works but it is too verbose
> // Function fct = ({ Integer n ->
> //  -n
> // } as Function)
>
> println fct.apply(10)
> }
> }
>
> The error:
>
> Test.groovy: 9: [Static type checking] - Incompatible generic argument
> types. Cannot assign java.util.function.Function  groovy.lang.Closure> to: java.util.function.Function 
>  @ line 9, column 36.
> Function fct = { Integer n ->
>   ^
> 1 error
>
> [Finished in 0.5s]
>
> Is there a bug in groovy related to @CompileStatic or maybe I am missing
> something else? I just don't want to write redundant code.
>
> Thanks,
> Mihai
>
>
>
> --
> View this message in context: http://groovy.329449.n5.
> nabble.com/Static-type-checking-tp5735162.html
> Sent from the Groovy Users mailing list archive at Nabble.com.
>


Re: Static type checking

2016-09-02 Thread cazacugmihai
Hi Jason,

I want to use something like this:

Function fct1 = { ... } // without as Function String>
> Function fct2 = { ... } // -- // -- // --
> Function fct1 = { ... } // -- // -- // --
> chain(fct1, fct2, fct3) { ... }


It is a pity that Groovy has this issue.

Thanks,
Mihai




--
View this message in context: 
http://groovy.329449.n5.nabble.com/Static-type-checking-tp5735162p5735165.html
Sent from the Groovy Users mailing list archive at Nabble.com.

RE: Static type checking

2016-09-02 Thread Winnebeck, Jason
Looks like a bug to me, I can reproduce in 2.4.7. The good news is that if you 
have a method taking the Function, like:

static void calc(Function fct) { println fct.apply(10) }

Then you can call it with calc { -it }

You can use the trick to define an identity function to trick the static 
compiler:

static Function f(Function fct) { fct }
Function fct = f { -it }

However, I could not get the following signature to work:

static  Function f(Function fct) { fct }

If you don't need full type checking, the following does work:
Function fct = { Integer n ->
return 1
}

Jason

-Original Message-
From: cazacugmihai [mailto:cazacugmi...@gmail.com] 
Sent: Friday, September 02, 2016 9:06 AM
To: us...@groovy.incubator.apache.org
Subject: Static type checking

Hi, 

I have a problem running this code:
 
import groovy.transform.CompileStatic
import java.util.function.Function
 
@CompileStatic
class Test {
static void main(String[] args) {
   // this code fails 
Function fct = { Integer n ->
-n
}
 
// this one works but it is too verbose
// Function fct = ({ Integer n ->
//  -n
// } as Function)
 
println fct.apply(10)
}
}

The error:

Test.groovy: 9: [Static type checking] - Incompatible generic argument types. 
Cannot assign java.util.function.Function  to: java.util.function.Function   @ line 
9, column 36.
Function fct = { Integer n ->
  ^
1 error

[Finished in 0.5s]

Is there a bug in groovy related to @CompileStatic or maybe I am missing 
something else? I just don't want to write redundant code.

Thanks,
Mihai



--
View this message in context: 
http://groovy.329449.n5.nabble.com/Static-type-checking-tp5735162.html
Sent from the Groovy Users mailing list archive at Nabble.com.

This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.


Static type checking

2016-09-02 Thread cazacugmihai
Hi, 

I have a problem running this code:
 
import groovy.transform.CompileStatic
import java.util.function.Function
 
@CompileStatic
class Test {
static void main(String[] args) {
   // this code fails 
Function fct = { Integer n ->
-n
}
 
// this one works but it is too verbose
// Function fct = ({ Integer n ->
//  -n
// } as Function)
 
println fct.apply(10)
}
}

The error:

Test.groovy: 9: [Static type checking] - Incompatible generic argument
types. Cannot assign java.util.function.Function  to: java.util.function.Function 
 @ line 9, column 36.
Function fct = { Integer n ->
  ^
1 error

[Finished in 0.5s]

Is there a bug in groovy related to @CompileStatic or maybe I am missing
something else? I just don't want to write redundant code.

Thanks,
Mihai



--
View this message in context: 
http://groovy.329449.n5.nabble.com/Static-type-checking-tp5735162.html
Sent from the Groovy Users mailing list archive at Nabble.com.


Question about AST Transforms and @DelegatesTo

2016-09-02 Thread Dogbert
So I have a question about AST Transforms and @DelegatesTo, as it would
relate to AST transforms in a Grails plugin I wrote:
https://github.com/virtualdogbert/Enforcer

I don't think I can use @DelegatesTo as is, but, if I could figure out how
it works, could I write a new version of @DelegatesTo, that I could apply
to the parameters of an AST transform like:

https://github.com/virtualdogbert/Enforcer/blob/master/src/main/groovy/com/
virtualdogbert/ast/Enforce.groovy

https://github.com/virtualdogbert/Enforcer/blob/master/src/main/groovy/com/
virtualdogbert/ast/EnforceASTTransformation.groovy

So that I could convince an IDE like intellij that those closure parameters
delegate to a service class, so that when I use methods from that service
class or it's traits, the IDE wont mark them as unresolved.

Thank you for reading, and any help or direction you might provide.

-Tucker