You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/10/22 23:32:27 UTC

[jira] [Commented] (GROOVY-6835) flow typing activated by if statement doing an "instanceof" check doesn't work as expected with interface types

    [ https://issues.apache.org/jira/browse/GROOVY-6835?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14969939#comment-14969939 ] 

Shil Sinha commented on GROOVY-6835:
------------------------------------

This doesn't occur in any versions since 2.4.2 (inclusive) or in Master, so it was probably fixed as a side effect.

> flow typing activated by if statement doing an "instanceof" check  doesn't work as expected with interface types
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-6835
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6835
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.3.2, 2.4.0-rc-1
>            Reporter: Lari Hotari
>            Assignee: Cédric Champeau
>
> The following code example fails with this STC error in compilation:
> {code}
> 1 compilation error:
> [Static type checking] - Cannot call java.util.Set <CharSequence>#add(java.lang.CharSequence) with arguments [<UnionTypejava.lang.Object+java.lang.CharSequence>] 
>  at line: 10, column: 12
> {code}
> {code}
> @groovy.transform.CompileStatic
> class ShowUnionTypeBug {
>     Map<String, Object> instanceMap = (Map<String,Object>)['a': 'Hello World']
>     def findInstance(String key) {
>         Set<CharSequence> allInstances = [] as Set
>         def instance = instanceMap.get(key)
>         if(instance instanceof CharSequence) {
>            allInstances.add(instance)
>         }
>         allInstances
>     }
> }
> new ShowUnionTypeBug().findInstance('a')
> {code}



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