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


You are not allowed to post comments on this tracker with your current authentication level.

bug #47618: NSPredicate: SELF implemented incorrectly

Submitted by:  Niels Grewe <thebeing>
Submitted on:  Mon 04 Apr 2016 02:56:49 PM UTC  
Category: Base/FoundationSeverity: 3 - Normal
Item Group: BugStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: In Test

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>
Project 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>
Project Member


No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 09 Apr 2017 12:58:06 PM UTCCaSStatusNone=>Fixed
      Open/ClosedOpen=>In Test

    Back to the top

    Powered by Savane 3.1-cleanup1