You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/12/21 01:46:00 UTC
[jira] [Commented] (GROOVY-9860) compilation error when passing a
closure's genericized parameters to a constructor under static compilation
[ https://issues.apache.org/jira/browse/GROOVY-9860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17252559#comment-17252559 ]
Eric Milles commented on GROOVY-9860:
-------------------------------------
I'm not sure what sense this makes to have a type parameter that is not used on the parameter(s) or return type of a method. Couldn't you just leave off the type parameter and do this?
{code:groovy}
@groovy.transform.CompileStatic
class C {
static main(args) {
def binder = { a, b ->
Tuple.tuple(a, b)
}
binder('foo', 'bar')
}
}
{code}
> compilation error when passing a closure's genericized parameters to a constructor under static compilation
> -----------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-9860
> URL: https://issues.apache.org/jira/browse/GROOVY-9860
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.7
> Reporter: Jason Garrett
> Priority: Minor
>
> The following code:
> {code:java}
> package example
> import groovy.transform.CompileStatic
> @CompileStatic
> class Tuple2Example {
> static <T> void noLongerCompiles() {
> def closure = { T a, T b ->
> return new Tuple2<T, T>(a, b)
> }
> closure("foo", "bar")
> }
> }
> {code}
> Compiles in v3.0.6 and earlier, but in v3.0.7 results in the following compiler error:
> {code:java}
> [Static type checking] - Cannot find matching method groovy.lang.Tuple2#<init>(T, T). Please check if the declared type is correct and if the method exists. @ line 10, column 11. return new Tuple2<T, T>(a, b) ^
> 1 error
> {code}
> Because this compiles in all versions prior to 3.0.7, I figure it should compile 3.0.7 too. Even if it really shouldn't compile the message probably ought to be something about the inability to infer the types of a and b, not that the constructor can't be found.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)