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

Paul King commented on GROOVY-11744:
------------------------------------

I expect it to work without @CompileStatic:

{noformat}
$ cat main.groovy 
def main() {
  def  (_, y, _) = [3, 4, 5]
  println _ // 5, last usage
  println GroovySystem.version
}
$ ~/Developer/groovy-5.0.0/bin/groovy main.groovy 
5
5.0.0
{noformat}
But with @CompileStatic I expect the compilation error: 
{noformat}
$ vi main.groovy 
$ cat main.groovy                                
@groovy.transform.CompileStatic
def main() {
  def  (_, y, _) = [3, 4, 5]
  println _ // 5, last usage
  println GroovySystem.version
}
$ ~/Developer/groovy-5.0.0/bin/groovy main.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/main.groovy: 4: [Static type checking] - The variable [_] is 
undeclared.
 @ line 4, column 11.
     println _ // 5, last usage
             ^
1 error
{noformat}

> Unnamed variables are actually used
> -----------------------------------
>
>                 Key: GROOVY-11744
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11744
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Georgii Ustinov
>            Priority: Major
>
> I am currently implementing Groovy 5 support inside Intellij IDEA and 
> encountered the following behaviour. Consider the following code:
> {code:java}
> package org.example.demo
> static void main(String[] args) {
>     def _ = 1
>     def (_, _) = [2, 3]
>     println _
> } {code}
> I expected that it will print 1, since variable declaration contains only 
> unnamed variables.
> Actually it prints 3. The same behaviour can be encountered here:
> {code:java}
> def _ = 1
> def x = (_, _) -> {
> println(_)
> }
> x(2, 3){code}
> I beileve this is a bug. 



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

Reply via email to