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 01:34:00 UTC

[jira] [Updated] (GROOVY-7622) no auto-conversion to generic type argument

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

Paul King updated GROOVY-7622:
------------------------------
    Description: 
Generic type argument doesn't force type conversion, leading to runtime exceptions. Two such cases are included in the test below.

{code}
import org.junit.Test

class AutoConvertingToGenericTypeArguments {
    @Test
    void "value in map constructor parameter converted to generic type argument"() {
        Person p = new Person(id: 1);
        assert p.id.class == Long // fails, actual class is Integer
    }

    @Test
    //@CompileStatic unintuitively makes the test pass
    void "setter parameter converted to generic type argument"() {
        Person p = new Person();
        p.id = 1
        assert p.id.class == Long // fails, actual class is Integer 
    }

    class Entity<ID> { ID id; }
    class Person extends Entity<Long> {}
}
{code}

  was:
Generic type argument doesn't force type conversion, leading to runtime exceptions. Two such cases are included in the test below.

{code}
class AutoConvertingToGenericTypeArguments {
    @Test
    void "value in map constructor parameter converted to generic type argument"() {
        Person p = new Person(id: 1);
        assert p.id.class == Long // fails, actual class is Integer
    }

    @Test
    //@CompileStatic unintuitively makes the test pass
    void "setter parameter converted to generic type argument"() {
        Person p = new Person();
        p.id = 1
        assert p.id.class == Long // fails, actual class is Integer 
    }

    class Entity<ID> { ID id; }
    class Person extends Entity<Long> {}
}
{code}


> no auto-conversion to generic type argument
> -------------------------------------------
>
>                 Key: GROOVY-7622
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7622
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.5
>            Reporter: Andrei Amariei
>            Priority: Major
>
> Generic type argument doesn't force type conversion, leading to runtime exceptions. Two such cases are included in the test below.
> {code}
> import org.junit.Test
> class AutoConvertingToGenericTypeArguments {
>     @Test
>     void "value in map constructor parameter converted to generic type argument"() {
>         Person p = new Person(id: 1);
>         assert p.id.class == Long // fails, actual class is Integer
>     }
>     @Test
>     //@CompileStatic unintuitively makes the test pass
>     void "setter parameter converted to generic type argument"() {
>         Person p = new Person();
>         p.id = 1
>         assert p.id.class == Long // fails, actual class is Integer 
>     }
>     class Entity<ID> { ID id; }
>     class Person extends Entity<Long> {}
> }
> {code}



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