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

Fix style parsing bug for constant expressions #11606

Merged
merged 4 commits into from
Apr 9, 2018
Merged

Conversation

anandthakker
Copy link
Contributor

Closes #10849

} else {
// we didn't manage to fold to a literal during parsing, so evaluate it now
EvaluationContext params(nullptr);
EvaluationResult evaluated((*expression)->evaluate(params));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to check for heatmap-density or other computed properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good question -- heatmap-density is used only in heatmap-color, which isn't data-driven and so isn't parsed as a DataDrivenPropertyValue. Rather, it actually has its own wrapper HeatmapColorPropertyValue

Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to fix this by eliminating the edge cases that cause ParsingContext::parse not to evaluate to a literal when it could, rather than adding another place where constant expression evaluation can happen?

I don't really understand the "to-color" example in #10849 (comment). Isn't adding the coercion and then checking isConstant the correct order?

For the let/var example, it seems like isConstant should follow vars.

@anandthakker
Copy link
Contributor Author

Wouldn't it be better to fix this by eliminating the edge cases that cause ParsingContext::parse not to evaluate to a literal when it could, rather than adding another place where constant expression evaluation can happen

Yeah, definitely - I figured I'd submit this narrow fix (since it's very straightforward) and then follow up with the "right" one here and in GL JS.

I don't really understand the "to-color" example in #10849 (comment). Isn't adding the coercion and then checking isConstant the correct order?

Yes, this is the correct order. The bug is that we incorrectly assume an expression is constant only if its immediate children are all literals. In spirit, this assumption makes sense, since any constant child expression should have been collapsed to a constant when it was parsed. But in the case where an inferred type assertion/coercion has been inserted, this assumption fails to be true, and so we don't fold it to a literal.

@anandthakker
Copy link
Contributor Author

The more complete fix @jfirebaugh suggested wasn't as involved as I'd feared -- pushed it in 986d659 but now need to update some expression tests that no longer test the intended expression (because it gets folded away 😂 ) and add tests for the edge cases that this covers.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants