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.

Style parsing fails for constant expression values #10849

Closed

Description

@jfirebaugh

Triggered by the following style:

{
        "version": 8,
        "layers": [{
            "id": "symbol",
            "type": "symbol",
            "source": "vector",
            "layout": {
              "text-font": ["array", "string", ["literal", ["Helvetica"]]]
            }
        }]
}

cc @anandthakker

Activity

  1. added this to the milestone on Jan 6, 2018
  2. changed the title [-]Assertion failed: (false), function operator(), src/mbgl/style/expression/find_zoom_curve.cpp, line 65.[/-] [+]Style parsing fails for constant expression values[/+] on Feb 22, 2018
  3. anandthakker commented on Feb 22, 2018

    @anandthakker
    Contributor

    The issue here is that in Converter<DataDrivenPropertyValue<T>>, we're assuming that any expression value must be a camera, source, or composite expression.

  4. added
    Core
    on Feb 23, 2018
  5. anandthakker commented on Apr 5, 2018

    @anandthakker
    Contributor

    #11282 did not fully fix this issue. The assertion in

    if (featureConstant && !zoomConstant) {
    return DataDrivenPropertyValue<T>(CameraFunction<T>(std::move(*expression)));
    } else if (!featureConstant && zoomConstant) {
    return DataDrivenPropertyValue<T>(SourceFunction<T>(std::move(*expression)));
    } else if (!featureConstant && !zoomConstant) {
    return DataDrivenPropertyValue<T>(CompositeFunction<T>(std::move(*expression)));
    } else {
    // If an expression is neither zoom- nor feature-dependent, it
    // should have been reduced to a Literal when it was parsed.
    auto literal = dynamic_cast<Literal*>(expression->get());
    assert(literal);
    optional<T> constant = fromExpressionValue<T>(literal->getValue());

    fails in the following cases:

    • ["to-color", ["get", "x", ["literal", {"x": "red"}]] -- because we add the to-color annotation before checking isConstant() (and isConstant assumes that all of its argument's children have already been folded to literals if possible)
    • ["let", "x", 1, ["var", "x"]] -- because we conservatively just bail out of isConstant when we see a var expression

    The quick fix would be to replace the last three lines above with:

    optional<T> constant;
    if (auto literal = dynamic_cast<Literal*>(expression->get()) {
        // cool, it's pre-folded to a literal
        constant = fromExpressionValue<T>(literal->getValue());
    } else {
        // we didn't manage to fold to a literal during parsing, so evaluate it now
        EvaluationContext params(nullptr);
        EvaluationResult evaluated((*parsed)->evaluate(params));
        assert(evaluated); // this assert really should work, since we've already checked above that the expression is zoom- & feature-constant.
        constant = fromExpressionValue<T>(*evaluated);
    }

    The fuller fix would be to fix constant folding during parsing to work during every case.

  6. anandthakker commented on Apr 10, 2018

    @anandthakker
    Contributor

    Fixed in #11606

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

    Core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions