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 2021/10/29 21:11:00 UTC

[jira] [Assigned] (GROOVY-7142) type inference problem with List of Interface and List of the class which implements the interface

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

Eric Milles reassigned GROOVY-7142:
-----------------------------------

    Assignee: Eric Milles

> type inference problem with List of Interface and List of the class which implements the interface
> --------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7142
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7142
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.0-beta-3
>         Environment: Groovy Version: 2.4.0-beta-1 JVM: 1.8.0_25 Vendor: Oracle Corporation OS: Mac OS X
>            Reporter: UEHARA Junji
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: error3.groovy
>
>
> following code (attached) emits [Static type checking] - Incompatible generic argument types. Cannot assign java.util.List <Func> to: java.util.List <IFunc>
> {code}
> import groovy.transform.TypeChecked
> interface IFunc<T> {
>     void apply(T t);
> }
> class Func<T> implements IFunc<T> {
>     void apply(T t){}
> }
> @TypeChecked
> def test(IFunc<Integer> f1) {
>     List<IFunc<Integer>> list1 = [f1] // OK. type of [f1] is List<IFunc<Integer>>
>     IFunc<Integer> f2 = new Func<Integer>()
>     List<IFunc<Integer>> list2 = [f2] // [Static type checking] - Incompatible generic argument types. Cannot assign java.util.List <Func> to: java.util.List <IFunc>
>                                       // why? type of f1 and f2 looks same.
>     IFunc<Integer> f3 = new Func<Integer>() as IFunc<Integer> //with coercion
>     List<IFunc<Integer>> list3 = [f3] // OK
>     IFunc<Integer> f4 = null
>     if (true) {
>         f4 = new Func<Integer>()
>     }
>     List<IFunc<Integer>> list4 = [f4] // OK. but why? type of f3 looks same as type of f2.
>     
> }
> @TypeChecked
> def test2() {
>     IFunc<Integer> f = new Func<Integer>()
>     test(f)
> }
> test2()
> {code}
> is this a specification?
> above case is for assignment but method parameter passing makes same STC error.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)