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

Support `BlockExpression` to treat statement as expression

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      We need unify expression and statement by introduing BlockExpression to support new features. BlockExpression creates a new variable scope and allows yield to produce the final result, thus statement could be used where expression appears, e.g.

      • GROOVY-9272 could leverage the power of this improvement to treat statement as expression.
      • def v = if (pass) 'Yes' else 'No'
      • def v = while(cnt < 3) {
           if (pass) yield 'Yes' // produce the value for BlockExpression (Note: default value is null)
           cnt++
        }
        

      Note: we do not introduce any new syntax for BlockExpression but just introduce a new AST node

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: