[
https://issues.apache.org/jira/browse/GROOVY-10222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17419265#comment-17419265
]
Eric Milles commented on GROOVY-10222:
--------------------------------------
Similar case for return instead of assign:
{code:groovy}
class Task {
def <T> T exec(args) {
args // or ...
}
}
class Test {
Task task
@groovy.transform.TypeChecked
def <T> T exec(args) {
task.exec(args) // Cannot return value of type #T on method returning type T
}
}
{code}
> Unable to infer the type parameter of a parameterized function
> --------------------------------------------------------------
>
> Key: GROOVY-10222
> URL: https://issues.apache.org/jira/browse/GROOVY-10222
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Major
>
> I have the following program
> {code:java}
> class A {
> static <T> T foo() {
> return null;
> }
> }
> class Test<T> {
> void bar() {
> T x = A.foo();
> }
> }
> {code}
> h3. Actual Behaviour
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> groovy11.groovy: 9: [Static type checking] - Cannot assign value of type #T
> to variable of type T
> @ line 9, column 15.
> T x = A.foo();
> ^1 error
> {code}
> h3. Expected Behaviour
> Compile successfully
>
> I don't know however, if this is a limitation of the inference engine of
> groovyc or a bug. Note that the Java compiler compiles the above program
> successfully. Also note that if I replace "T x = A.foo()" with "String x =
> A.foo()", groovyc compiles the updated program.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)