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

Expression underlying a spread map expression is evaluated twice

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7-beta-1, 2.2.0-beta-1, 2.4.3
    • 4.0.0-beta-1, 3.0.9, 2.5.16
    • Compiler
    • None

    Description

      class SpreadMapBug extends GroovyTestCase {
          void test() {
              def x = 0
              assertEquals([a:1, b:1], [a:1, *:[b:++x]]) // fails; actual value: [a:1, b:2]
          }
      }
      

      Maybe this bug is related to the (strange) AST representation for a spread map expression (at least that's how I found the bug):
      "*:[b:++x]" is a MapEntryExpression whose

      • key is a SpreadMapExpression whose expression is a MapExpression representing "[b:++x]"
      • value is a MapExpression representing "[b:++x]".

      That makes two MapExpressionS...

      Attachments

        Activity

          People

            emilles Eric Milles
            pniederw Peter Niederwieser
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: