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

ASF GitHub Bot commented on GROOVY-11492:
-----------------------------------------

eric-milles commented on PR #3054:
URL: https://github.com/apache/groovy/pull/3054#issuecomment-7259265848

   I remove the compatibility note so it would no longer be a source of 
conflict.  Here it is:
   
   ### Groovy 7 — Java-style array initialization and promotion of scalar to 
array (GROOVY-8561, GROOVY-11492)
   
   The Java array initializer syntax uses curly braces, which Groovy has used 
for
   code blocks (closures, lambdas, methods) until the Parrot Parser introduced 
in
   Groovy 3 added basic support for `new Type[]{...}` array expressions. This 
did
   not support multi-dimension init without verbose value expressions, like 
this:
   ```groovy
   def array = new int[][] { new int[] {1}, new int[] {2,3} }
   ```
   As of Groovy 5, this can be done more succinctly:
   ```groovy
   def array = new int[][] { {1}, {2,3} } // GROOVY-8551
   ```
   
   Groovy 6 took this one step further, supporting array literals for annotation
   attribute values (GROOVY-11485, GROOVY-11866). The next gap to close for Java
   is to support the terse syntax for field, variable or parameter declarations.
   ```groovy
   int[][] array = { {1}, {2,3} } // GROOVY-11492
   ```
   
   The one conflict that cannot be avoided has to do with Groovy's 
auto-promotion
   from a scalar to an array.
   ```groovy
   int[] a = 1 // array with single integer (1)
   String[] b = 'B'
   Closure[] c = {} // GROOVY-8561
   ```
   The array `c` in this example was a single-closure array due to promotion. 
For
   Groovy 7+, this indicates a zero-length array, as in all other array cases. 
If
   your code uses such auto-promotion behavior, you could add the outer braces 
or
   brackets. Or write a non-ambiguous closure literal with an arrow.




> Java compatibility: array initializers without "new Type[]"
> -----------------------------------------------------------
>
>                 Key: GROOVY-11492
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11492
>             Project: Groovy
>          Issue Type: Improvement
>          Components: parser-antlr4
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: arrays
>
> There are a few cases where bare array initializers are not yet supported:
> # {{int[][] array = \{ \{1,2\}, \{3,4\} \};}}
> # {{@Target(\{ ElementType.FIELD, ElementType.METHOD \})}}
> # {code:groovy}@interface A {
>   String[] strings() default {}
> }
> {code}
> These were implemented as part of [1] but the PR was closed.  It may be worth 
> looking back over what was done and re-implementing one or more of these 
> cases.  It was noted that {{Closure[] array = \{\};}} is one of the edge 
> cases that leads to ambiguity.
> [1] https://github.com/apache/groovy/pull/691



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to