Velocity
  1. Velocity
  2. VELOCITY-50

RFE: invalid parameters for #if directive should be a parse error?

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: PC

      Description

      The 3 lines below will print two No-s and one Yes:
      #if('foo') Yes #else No #end
      #if(1) Yes #else
      No #end
      #if(true) Yes #else No #end

      while the 4 lines bellow will print two Yes-es as
      expected:
      #set($x = 'foo')
      #if($x) Yes #else No #end
      #set($x = 1)
      #if($x) Yes #else No
      #end

      Also, the 2 lines below will print false:
      #set($x = 'x' && true)
      $x

      (Please
      ignore possible false line breaks inserted by bugzilla.)

      Tried with 1.2 Stable and 1.3
      Nightly 22/03

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Reopened Reopened Resolved Resolved
        2004d 11h 1 Will Glass-Husain 18/Sep/07 04:48
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551872 ] jira [ 12552665 ]
        Mark Thomas made changes -
        Workflow jira [ 12324925 ] Default workflow, editable Closed status [ 12551872 ]
        Will Glass-Husain made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]
        Hide
        Will Glass-Husain added a comment -

        This is expected behavior for Velocity at this point. #if can be used to detect boolean values or to detect existence of a reference.

        Show
        Will Glass-Husain added a comment - This is expected behavior for Velocity at this point. #if can be used to detect boolean values or to detect existence of a reference.
        Henning Schmiedehausen made changes -
        Component/s Engine [ 12311337 ]
        Component/s Source [ 12310214 ]
        Bugzilla Id 7386
        Will Glass-Husain made changes -
        Bugzilla Id 7386
        Assignee Velocity-Dev List [ velocity-dev@jakarta.apache.org ]
        Description The 3 lines below will print two No-s and one Yes:
          #if('foo') Yes #else No #end
          #if(1) Yes #else
        No #end
          #if(true) Yes #else No #end

        while the 4 lines bellow will print two Yes-es as
        expected:
          #set($x = 'foo')
          #if($x) Yes #else No #end
          #set($x = 1)
          #if($x) Yes #else No
        #end

        Also, the 2 lines below will print false:
          #set($x = 'x' && true)
          $x

        (Please
        ignore possible false line breaks inserted by bugzilla.)

        Tried with 1.2 Stable and 1.3
        Nightly 22/03
        The 3 lines below will print two No-s and one Yes:
          #if('foo') Yes #else No #end
          #if(1) Yes #else
        No #end
          #if(true) Yes #else No #end

        while the 4 lines bellow will print two Yes-es as
        expected:
          #set($x = 'foo')
          #if($x) Yes #else No #end
          #set($x = 1)
          #if($x) Yes #else No
        #end

        Also, the 2 lines below will print false:
          #set($x = 'x' && true)
          $x

        (Please
        ignore possible false line breaks inserted by bugzilla.)

        Tried with 1.2 Stable and 1.3
        Nightly 22/03
        Fix Version/s 1.6 [ 12310290 ]
        Environment Operating System: All
        Platform: PC
        Operating System: All
        Platform: PC
        Hide
        Will Glass-Husain added a comment -

        I like the idea of adding a log message. Setting for v1.6

        Show
        Will Glass-Husain added a comment - I like the idea of adding a log message. Setting for v1.6
        Jeff Turner made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 7386 12314920
        Hide
        Daniel Dekany added a comment -

        Ammm... sorry for reopeing this. I accept your argument, but should not it be a parse error then?
        Or at least an error in the log?

        Show
        Daniel Dekany added a comment - Ammm... sorry for reopeing this. I accept your argument, but should not it be a parse error then? Or at least an error in the log?
        Hide
        Geir Magnusson Jr added a comment -

        This is due to the fact that you are misinterpreting the semantics of #if().
        This isn't C - #if(), which I think is broken in other ways, checks to see if
        either it's boolean valued (and true) or in the context. The literal 1 or 'foo'
        are neither... Marking as not a bug - feel free to debate on the list. We can
        always just re-open

        Show
        Geir Magnusson Jr added a comment - This is due to the fact that you are misinterpreting the semantics of #if(). This isn't C - #if(), which I think is broken in other ways, checks to see if either it's boolean valued (and true) or in the context. The literal 1 or 'foo' are neither... Marking as not a bug - feel free to debate on the list. We can always just re-open
        Daniel Dekany created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Daniel Dekany
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development