Comments (6)
Does anyone know how to fix this? I took a brief look but having a little trouble following the NSPredicate implementation.
Fixed in #273
from libs-base.
The following patch fixes this bug (and doesn't cause any of the existing NSPredicate tests to fail), but I suspect it may just be a bandaid for a specific case of a more general problem.
--- NSPredicate.m.orig 2022-01-29 14:18:23.249998976 +0000
+++ NSPredicate.m 2022-01-29 15:34:39.745337585 +0000
@@ -1049,6 +1049,8 @@
e = [rightResult objectEnumerator];
while ((value = [e nextObject]))
{
+ if ([value isKindOfClass:[GSConstantValueExpression class]])
+ value = [value constantValue];
if ([value isEqual: leftResult])
return YES;
}
from libs-base.
I've never used NSPredicate, but looking through the code it seems to me the issue might be with the GSConstantValueExpression class used to represent the array.
I wonder if its -expressionValueWithObject:context: method should, in the case of an array, return a new array formed by calling that method on each of its elements. What do you think?
from libs-base.
Yes, the following patch does seem more general, fixes my use case, and doesn't break the existing NSPredicate tests:
--- NSPredicate.m.orig 2022-01-30 10:27:07.177865334 -0500
+++ NSPredicate.m 2022-01-30 10:36:17.211753217 -0500
@@ -1337,7 +1337,15 @@
- (id) expressionValueWithObject: (id)object
context: (NSMutableDictionary *)context
{
+ if ([_obj isKindOfClass:[NSArray class]]) {
+ NSMutableArray *tmp = [NSMutableArray arrayWithCapacity:[_obj count]];
+ for (id o in _obj) {
+ [tmp addObject:[o expressionValueWithObject:o context:context]];
+ }
+ return tmp;
+ } else {
return _obj;
+ }
}
from libs-base.
I wrote/added a portable (not dependent on objc-2) version of that solution.
from libs-base.
This fix doesn’t work when the array is given as an argument instead of inside the format string like this:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self IN %@", @[@"yes"]];
NSArray *filteredElements = [@[@"yes", @"no"] filteredArrayUsingPredicate:predicate];
NSLog(@"Elements: %@", filteredElements);
Running the above crashes in line 1351 here, because e
will be an NSString ("yes") instead of an NSExpression:
libs-base/Source/NSPredicate.m
Lines 1348 to 1354 in f334462
Does anyone know how to fix this? I took a brief look but having a little trouble following the NSPredicate implementation.
from libs-base.
Related Issues (20)
- NSException.m:1450:7: error: '_objc_unexpected_exception' undeclared HOT 5
- removeObserver:forKeyPath:context: not implemented HOT 2
- Various issues with Key-Value Observing implementation HOT 4
- NSFileHandle - truncateAtOffset:error:
- NSKeyValueObserving - removeObserver:fromObjectsAtIndexes:forKeyPath:context: not implemented. HOT 2
- [autogsdoc] doc file generation date HOT 2
- [autogsdoc] Obj-C 2.0 syntax support HOT 1
- GSMacOSXCompatible default turns on some unintended things HOT 6
- NSRegularExpression does not populate error if expression is invalid HOT 2
- NSISO8601DateFormatter generates noncompliant strings HOT 1
- Speedup CI by using prebuild debian packages HOT 3
- -[NSTask launch] fails to close all file descriptors in child HOT 5
- Update Dependencies in Texinfo HOT 1
- Notes for next Release (1.30.0) HOT 4
- -[NSArray filteredArrayUsingPredicate:] should ignore NSNull values HOT 4
- [autogsdoc] cumulative issues
- NSBundle loads resources from the wrong version HOT 18
- awakeFromNib is implemented on NSObject (category in AppKit) and not on NSView HOT 1
- Avahi code doesn't compile HOT 2
- Failing tests on Alpine Linux HOT 25
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libs-base.