You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2016/10/05 23:06:20 UTC

[jira] [Comment Edited] (GROOVY-7958) Incorrect parsing of comma-separated variable declaration as single statement after if/while/for

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

Paul King edited comment on GROOVY-7958 at 10/5/16 11:05 PM:
-------------------------------------------------------------

Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/437#discussion_r82088116
  
    [--snip--]
    +    void testCoomaSepVariableDeclarationAfterIf() {
    --- End diff --
    
    fixed



was (Author: githubbot):
Github user paulk-asert commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/437#discussion_r82088116
  
    --- Diff: src/test/groovy/bugs/Groovy7958Bug.groovy ---
    @@ -0,0 +1,31 @@
    +/*
    + *  Licensed to the Apache Software Foundation (ASF) under one
    + *  or more contributor license agreements.  See the NOTICE file
    + *  distributed with this work for additional information
    + *  regarding copyright ownership.  The ASF licenses this file
    + *  to you under the Apache License, Version 2.0 (the
    + *  "License"); you may not use this file except in compliance
    + *  with the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + *  Unless required by applicable law or agreed to in writing,
    + *  software distributed under the License is distributed on an
    + *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + *  KIND, either express or implied.  See the License for the
    + *  specific language governing permissions and limitations
    + *  under the License.
    + */
    +package groovy.bugs
    +
    +class Groovy7958Bug extends GroovyTestCase {
    +    void testCoomaSepVariableDeclarationAfterIf() {
    --- End diff --
    
    fixed


> Incorrect parsing of comma-separated variable declaration as single statement after if/while/for
> ------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7958
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7958
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>             Fix For: 2.4.8
>
>
> Currently during parsing a single (comma-separated) variable declaration is turned into multiple statements on the fly. If this occurs when such a statement is the single statement after an if/while/for, then only the first statement is picked up and the next is left dangling within the AST tree. For 'if' it becomes the else statement! while in the 'for/while' cases I think it is ignored. So, the following code doesn't work as expected:
> {code}
> int xNext = 0, yNext = 0
> if (false) int x = xNext++, y = yNext++
> assert xNext == 0 && yNext == 0
> if (true) int x = xNext++, y = yNext++
> assert xNext == 1 && yNext == 1
> {code}
> This is very much an edge case (what good is a declaration if you then have no block in which to use it?) but is still worth fixing.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)