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 2018/08/26 03:14:00 UTC

[jira] [Closed] (GROOVY-6681) Generic method fails signature match with optional arguments

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

Paul King closed GROOVY-6681.
-----------------------------
    Resolution: Cannot Reproduce
      Assignee: Paul King

This looks like it has been fixed several versions ago. Please re-open if you still have problems with the latest version of Groovy.

> Generic method fails signature match with optional arguments
> ------------------------------------------------------------
>
>                 Key: GROOVY-6681
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6681
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.2.2, 2.4.0-beta-3
>            Reporter: Sean True
>            Assignee: Paul King
>            Priority: Major
>
> The following  code fails to compile with @CompileStatic, although it appears to be syntactically correct.
> A work around is to declare the method with two signatures instead.
> The compiler error is:
> [Static type checking] - Cannot assign value of type T to variable of type bugreport.test.ExtensionOne
> {code:java}
> package bugreport.test
> import groovy.transform.CompileStatic
> class Base
> {
> }
> class ExtensionOne extends Base
> {
> }
> class ExtensionTwo extends Base
> {
> }
> class GenericMethodTest
> {
>   public <T extends Base> T get(Class<T> cls, key="")
>   {
>     return cls.newInstance()
>   }
> }
> @CompileStatic
> class TestGenericMethod
> {
>   TestGenericMethod()
>   {
>     GenericMethodTest genericMethodTest = new GenericMethodTest()
>     ExtensionTwo extensionTwo = genericMethodTest.get(ExtensionTwo.class, "foo")
>     // Compiling this fails with the message:
>     // Error:(31, 33) Groovyc: [Static type checking] - Cannot assign value of type T to variable of type bugreport.test.ExtensionOne
>     ExtensionOne extensionOne = genericMethodTest.get(ExtensionOne.class)
>   }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)