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

Eric Milles updated GROOVY-11137:
---------------------------------
    Description: 
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}

JLS intersection types: 
https://docs.oracle.com/javase/specs/jls/se19/html/jls-4.html#jls-4.9
JLS union types (mentioned under try/catch): 
https://docs.oracle.com/javase/specs/jls/se19/html/jls-14.html#jls-14.20


  was:
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}


> 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}
> JLS intersection types: 
> https://docs.oracle.com/javase/specs/jls/se19/html/jls-4.html#jls-4.9
> JLS union types (mentioned under try/catch): 
> https://docs.oracle.com/javase/specs/jls/se19/html/jls-14.html#jls-14.20



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

Reply via email to