bugGNUstep - Bugs: bug #47618, NSPredicate: SELF implemented...

Group
 
 

bug #47618: NSPredicate: SELF implemented incorrectly

Submitter:  Niels Grewe <thebeing>
Submitted:  Mon 04 Apr 2016 02:56:49 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  In Test
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 09 Apr 2017 12:58:06 PM UTC, comment #1: 

While I'm not very familiar with the NSPredicated code, and don't use it myself, I've made some changes to at least fix the specific case mentioned.

It looked to me like the primary issue is that [GSEvaluatedObjectExpression expressionValueWithObject:context:] was returning self rather than its ageument, so I changed that.
It also failed to implement -keyPath ... causing an exception in the parser.
Also, the key path parsing was failing to realise that the case of SELF.foo actually means the key path is just 'foo'.

Finally your example comparison failed because the value in the dictionary was a string.   I guess that the <, >, <= and >= operators are supposed to be numeric, so I changed the code to use -doubleValue for the arguments to those operators.

Richard Frith-Macdonald <CaS>
Group Member
Mon 04 Apr 2016 02:56:49 PM UTC, original submission:  

The SELF expression in NSPredicate is implemented in a way that only allows it to be used as LHS or RHS expression in an NSComparison predicate.

In particular, the following is legal under Cocoa:

  NSDictionary *a = [NSDictionary dictionaryWithObjectsAndKeys:
    @"2", @"foo", nil];
  NSPredicate *p = [NSPredicate predicateWithFormat: @"SELF.foo <= 2"];
  [p evaluateWithObject: a];

The base implementation gives you:

Uncaught exception NSInvalidArgumentException, reason: [GSEvaluatedObjectExpression-keyPath] should be overridden by subclass

You can even do more complicated expressions such as "bar[SELF.foo]", where SELF is not a top-level expression in Cocoa.

The reason is that GSEvaluatedObjectExpression is created as a singleton, and always returns itself from expressionValueWithObject:context:, and there is some pointer equality checking in NSComparisonPredicate  to make it work for the really simple case (self == 'foo'). That totally sounds like premature optimisation to me, btw.

Niels Grewe <thebeing>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by thebeing (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-04-09 CaS StatusNone Fixed
        Open/ClosedOpen In Test

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code