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

Eric Milles commented on GROOVY-11168:
--------------------------------------

{{def <T> T m(@DelegatesTo(type="T") Closure c)}} does propagate the type 
parameter to the delegation metadata.  The rub here is that the return type 
inference comes after the closure/lambda parameter processing, which is where 
{{DelegatesTo}} is handled.

https://github.com/apache/groovy/blob/9e5bc22e66c1c462db3e5366b326450cb375cc15/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L2923

If you used a call like "this.<Type>Stub \{ ... \}" you could get the "T" 
resolved.  But that's probably not what you want.

https://github.com/apache/groovy/blob/9e5bc22e66c1c462db3e5366b326450cb375cc15/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L3317

> Ability to `@DelegatesTo` the return type
> -----------------------------------------
>
>                 Key: GROOVY-11168
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11168
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Björn Kautler
>            Priority: Major
>
> With a method
> {code:java}
> public <T> T Stub(Closure interactions); {code}
> that is then used like
> {code:java}
> Foo foo = Stub { /* configure the foo here */ } {code}
> I'd like to be able to specify that the delegate is of type {{T}} so in the 
> given example of type {{{}Foo{}}}.
> Currently we do this in Spock via IDE-specific gdsl/dsld Scripts.
> But it would be nice if this would be supported out of the box.
> (Ideally in 2.5 already, as we still have a 2.5 compatible artifact. :))



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to