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

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

[~lhotari] Would you like to submit a pr with your test?

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

Reply via email to