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

Eric Milles commented on GROOVY-11137:
--------------------------------------

Another union type example that does not work properly:
{code:groovy}
switch (object) {
  case Number:
  case String:
    object.somethingCommonToNumberAndString()
}
{code}

STC thinks the type of "object" is "(Number & String)" but it should be 
"(Number | String)".

> Improve support for union and intersection types
> ------------------------------------------------
>
>                 Key: GROOVY-11137
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11137
>             Project: Groovy
>          Issue Type: Improvement
>          Components: parser-antlr4, Static Type Checker
>            Reporter: Eric Milles
>            Priority: Major
>
> Union types are partially supported:
> {code:groovy}
> try {
>  foo()
> } catch (Exception | Error e) { // parses
>   e.printStackTrace() // flow type of e is probably Throwable but should be 
> (Exception | Error)
> }
> {code}
> But don't have direct representation or support in the AST.
> Intersection types (declared with {{&}}) are not supported:
> {code:groovy}
> // parses as method call: (a & b).call({ ... })
> var fun = (Function<String,String> & Serializable) { x -> x }
> void test(Number number) {
>   if (number instanceof Comparable) {
>     number // flow type is ? but should be (Number & Comparable)
>   }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to