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

        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.
        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
        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

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development