Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9484

Closure on the next line should not be treated as argument

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • None

    Description

      Here is the issue reported by a Spock user:

      in groovy 2.5

       modification                                | expected
       { Instant i, ZoneId z -> i.plusSeconds(1) } | defaultInstant.plusSeconds(1)
      

      these were treated as separate expressions
      in groovy 3.0 the closure gets merged as argument to the expected above.

       modification | this.expected({ Instant i, ZoneId z ->
                  i.plusSeconds(1)
              }) | defaultInstant.plusSeconds(1)
      

      I propose to unify the grammar of closure arguments:

      // 2 expressions: variable and closure
      meth
      { p ->
      }
      
      // 2 expressions: binary expression and closure
      a | meth
      { p ->
      }
      

      In the old grammar, the following code is parsed as method call with a closure argument.

      meth
      { p ->
      }
      

      Luckily, groovy-parser project containing source code of some famous groovy projects, none of which are broken because of the proposed change.

      See the discussion in the dev mailing list: http://groovy.329449.n5.nabble.com/About-eliminating-ambiguities-of-method-call-with-closure-argument-tt5766830.html

      Attachments

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              daniel_sun Daniel Sun
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m