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

Eric Milles updated GROOVY-6835:
--------------------------------
    Language: groovy

> 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: Paul King
>            Priority: Major
>             Fix For: 2.4.6
>
>
> 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
(v8.20.10#820010)

Reply via email to