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/23 15:49:00 UTC

[jira] [Resolved] (GROOVY-10328) STC: incorrect type inference for list, map, etc. with lower bound generics

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

Eric Milles resolved GROOVY-10328.
----------------------------------
    Fix Version/s: 4.0.0-beta-2
       Resolution: Fixed

> STC: incorrect type inference for list, map, etc. with lower bound generics
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-10328
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10328
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2
>
>
> Consider the following:
> {code:groovy}
> @groovy.transform.TypeChecked
> void test(List<? super String> list, Map<String, ? super String> map) {
>   def a = list.first()
>   def b = list.get(0)
>   def c = list[0]
>   def x = map.get('foo')
>   def y = map['foo']
>   def z = map.foo
> }
> {code}
> The type inferred for each of the local variables is String, which is an unsafe assumption.  Java infers Object for the same case (when "var" is used).



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