Menu

#473 String compares should have special exception for .nil

v4.2.0
closed
Classes (154)
complete
5
2014-04-15
2012-07-09
No

Currently, the string implementations of comparison operations unconditionally convert the right-hand-side of the comparison to a string value. This means compares like

if arg == .nil then ....

If the variable arg is .nil, then these objects are compared directly. If variable arg is a string value, .nil gets converted to the string "The NIL object" and this value is compared. This has two problems:

1) There is a potential for a false positive on this compare if the string value happens to be the string "The NIL object"
2) a NOSTRING condition is raised, which causes unexpected problems if SIGNAL ON ANY is in use.

The workaround is to code "if .nil == arg then ..." to get .nil on the left side of the operator. In practice, people almost universally prefer the first form. Comparison to .nil is such an important thing on the ooRexx language that the string class should recognize .nil as a special case and always return .false (avoiding the NOSTRING condition as well).

Related

Feature Requests: #457

Discussion

  • Rick McGuire

    Rick McGuire - 2012-08-21
    • status: open --> accepted
    • assigned_to: Rick McGuire
    • pending_work_items: --> code+doc+test
    • milestone: --> v4.2.0
     
  • Rick McGuire

    Rick McGuire - 2012-08-22
    • status: accepted --> pending
    • pending_work_items: code+doc+test --> complete
     
  • Rick McGuire

    Rick McGuire - 2012-08-22

    code committed [r8242]
    tests committed [r8243]
    docs committed [r8244]

     

    Related

    Commit: [r8242]
    Commit: [r8243]
    Commit: [r8244]

  • Rick McGuire

    Rick McGuire - 2012-08-27

    Some fixes for this feature

    code: [r8286]
    test: [r8287]

     

    Related

    Commit: [r8286]
    Commit: [r8287]

  • Rick McGuire

    Rick McGuire - 2014-04-15
    • status: pending --> closed
     

Anonymous
Anonymous

Add attachments
Cancel