Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Top-level aftermarket expression functions fail to parse #271

Open
1ec5 opened this issue Apr 18, 2020 · 2 comments
Open

Top-level aftermarket expression functions fail to parse #271

1ec5 opened this issue Apr 18, 2020 · 2 comments
Labels
archived documentation Improvements or additions to documentation expressions ios macOS wontfix This will not be worked on

Comments

@1ec5
Copy link
Contributor

1ec5 commented Apr 18, 2020

As of iOS 11.4 and macOS 10.15.4, if an “aftermarket” expression function like the ones added in mapbox/mapbox-gl-native#11472 appears at the top level of an NSExpression format string, it may raise an “Unable to parse the format string” exception unless certain syntaxes are used to make it an explicit function call. For example:

  • mgl_round(3.14159) 💥
  • mgl_round:(3.14159) ✔️
  • (mgl_round(3.14159)) ✔️
  • mgl_round(3.14159) + 0 ✔️
  • abs(mgl_round(3.14159)) ✔️

This issue affects any of the functions installed by +[MGLAftermarketExpressionInstaller installFunctions]:

// Install method-like functions, taking the number of arguments implied by
// the selector name.
INSTALL_METHOD(mgl_join:);
INSTALL_METHOD(mgl_round:);
INSTALL_METHOD(mgl_interpolate:withCurveType:parameters:stops:);
INSTALL_METHOD(mgl_step:from:stops:);
INSTALL_METHOD(mgl_coalesce:);
INSTALL_METHOD(mgl_does:have:);
INSTALL_METHOD(mgl_acos:);
INSTALL_METHOD(mgl_cos:);
INSTALL_METHOD(mgl_asin:);
INSTALL_METHOD(mgl_sin:);
INSTALL_METHOD(mgl_atan:);
INSTALL_METHOD(mgl_tan:);
INSTALL_METHOD(mgl_log2:);
INSTALL_METHOD(mgl_attributed:);
// Install functions that resemble control structures, taking arbitrary
// numbers of arguments. Vararg aftermarket functions need to be declared
// with an explicit and implicit first argument.
INSTALL_CONTROL_STRUCTURE(MGL_LET);
INSTALL_CONTROL_STRUCTURE(MGL_MATCH);
INSTALL_CONTROL_STRUCTURE(MGL_IF);
INSTALL_CONTROL_STRUCTURE(MGL_FUNCTION);

I suspect this regression is caused by a change in Apple’s iOS/macOS SDK, not the Mapbox Maps SDK. It’s possible that one of these private methods is responsible for raising the error. However, there probably isn’t much we can do about this issue, because we’re trying to avoid any potential App Store submission issues that would arise from calling any private method. We’re only extending the _NSPredicateUtilities class, which we’re only obtaining indirectly using official documented APIs.

In the absence of a fix, we should document this edge case in the “Predicates and Expressions” guide.

/cc @mapbox/maps-ios

@1ec5 1ec5 added ios expressions macOS status: triage documentation Improvements or additions to documentation labels Apr 18, 2020
@BRZErez
Copy link

BRZErez commented Aug 3, 2020

Is this still an issue?
I've spent a full day yesterday trying to make MGL_MATCH, MGL_IF, MGL_FUNCTION, TERNARY work and the app crashes all the time and couldn't understand why until I found this.
So why didn't you fix the docs to say that non of this is working anymore and need to use mgl_interpolate the very long way instead?
10x

@1ec5
Copy link
Contributor Author

1ec5 commented Aug 14, 2020

All the aftermarket expression functions do continue to work, but you need to surround them in parentheses if they’re at the top level of the expresion or predicate format string. See the ✔️ marks above.

TERNARY() works regardless. This is a syntax built into the Foundation framework, not a Mapbox-specific function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived documentation Improvements or additions to documentation expressions ios macOS wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants