You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2021/02/09 10:19:00 UTC

[jira] [Created] (GROOVY-9934) Bounded type parameter is not captured by closure

Thodoris Sotiropoulos created GROOVY-9934:
---------------------------------------------

             Summary: Bounded type parameter is not captured by closure
                 Key: GROOVY-9934
                 URL: https://issues.apache.org/jira/browse/GROOVY-9934
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation
    Affects Versions: 3.0.7
            Reporter: Thodoris Sotiropoulos


I have the following Groovy program

 

 
{code:java}
class Bar {}class Foo<T extends Bar> {
  public T method(T x) {
    def bar = {x}
    return bar()
  }
}
{code}
 

 
h3. Actual Behavior

The compiler raise the following compile-time error

 

 
{code:java}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 6: [Static type checking] - Cannot return value of type java.lang.Object on method returning type T
 @ line 6, column 12.
       return bar()
              ^1 error

{code}
h3. Expected Behavior

Compile successfully. Notably, when I remove the "extends" keyword from the type parameter, the code type checks as expected.

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)