You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/02/03 22:35:00 UTC

[jira] [Closed] (GROOVY-10098) Unexpected behaviour when the return type of a closure is a type parameter

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

Paul King closed GROOVY-10098.
------------------------------

> Unexpected behaviour when the return type of a closure is a type parameter
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-10098
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10098
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-1, 3.0.9
>
>
> This may be a recent regression.
> I have the following program
> {code:java}
> class Foo<T extends Number> {
>   T f  Foo(T f) {
>     this.f = f
>   }
>   T foo() {
>     Closure<T> clos = { -> f}
>     clos()
>   }
> }
> {code}
> h3. Actual behaviour
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 10: [Static type checking] - Cannot return value of type java.lang.Object on method returning type T
>  @ line 10, column 5.
>        clos()
>        ^1 error
> {code}
> h3. Expected behaviour
> Compile successfully
> h3. Comment
> The code works as expected if I remove the bound from the type parameter of class `Foo`.
>  
> Tested against https://github.com/apache/groovy/commit/f3d030afaaae44eca567ead74e68efb932831b08



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