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

conditional if/else has issues with evaluated strings in maps

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.5.0, 2.5.2, 2.5.4, 2.5.5
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      Ubuntu, Sun Java 8

      Description

      I was converting an if/else to a conditional and had the following error:

      class org.codehaus.groovy.ast.expr.TernaryExpression, with its value '((codeTotals[$it[1]] == null)) ? 0 : codeTotals[$it[1]]', is a bad expression as the left hand side of an assignment operator at line: 50 column: 87. 

      My if/else (which works)is as follows:

      if(codeTotals["${it[1]}"]==null){
      codeTotals["${it[1]}"] = 0
      }else{
      codeTotals["${it[1]}"] += 1
      }

       

      ... VS the  logical conditional (which throws the error):

      codeTotals["${it[1]}"] = (codeTotals["$it[1]"] == null) ? 0 : codeTotals["$it[1]"] +=1

       

      Right now I am just trying to test some features but I thought this was weird enough to mention since a logical should work the same regardless of variable.

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              orubel Owen Rubel
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: