Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Vararg aftermarket expression functions raise exceptions inside format strings #13026

Closed

Description

@1ec5

Using the MGL_FUNCTION(…) expression function inside an NSExpression or NSPredicate format string raises an exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unrecognized expression function MGL_FUNCTION:.'

The workaround is to use the %@ placeholder and set it to the result of passing MGL_FUNCTION into +[NSExpression expressionForFunction:arguments:].

The root cause is that this line only checks for MGL_FUNCTION function name, but NSExpression considers the function name to be MGL_FUNCTION:, with the extra colon, when there are any arguments:

} else if ([function isEqualToString:@"MGL_FUNCTION"]) {

So we need to check for both variants. While we’re at it, we should also add cases for MGL_IF: (not to be confused with mgl_if:, which takes a different set of arguments) and MGL_MATCH::

} else if ([function isEqualToString:@"MGL_IF"] ||
[function isEqualToString:@"mgl_if:"]) {
return self.mgl_jsonIfExpressionObject;
} else if ([function isEqualToString:@"MGL_MATCH"] ||
[function isEqualToString:@"mgl_match:"]) {
return self.mgl_jsonMatchExpressionObject;
} else if ([function isEqualToString:@"mgl_coalesce:"] ||
[function isEqualToString:@"mgl_coalesce"]) {

Once we fix #11720, we’ll end up having to distinguish between mgl_if: when used as a conventional function and mgl_if: when used as an aftermarket function.

/cc @fabian-guerra @captainbarbosa @riastrad @ChrisLoer

Activity

  1. added
    iOS
    macOS
    on Oct 3, 2018
  2. 1ec5 commented on Oct 3, 2018

    @1ec5
    ContributorAuthor

    This complicates the MGL_FUNCTION workaround for #12917 and #12739 to some degree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugiOSmacOSruntime styling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions