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

Andrei Amariei 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}
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
    }

    @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
    }

    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
>
> 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}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to