Skip to content

Commit

Permalink
Preserve expected type when parsing 'let' expressions (#7301)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley authored Sep 24, 2018
1 parent 23ac915 commit 395084c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/style-spec/expression/definitions/let.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Let implements Expression {
bindings.push([name, value]);
}

const result = context.parse(args[args.length - 1], args.length - 1, undefined, bindings);
const result = context.parse(args[args.length - 1], args.length - 1, context.expectedType, bindings);
if (!result) return null;

return new Let(bindings, result);
Expand Down
58 changes: 58 additions & 0 deletions test/integration/expression-tests/let/expected-value/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"expression": [
"let",
"density",
["/", ["get", "population"], ["get", "sq-km"]],
[
"interpolate",
["linear"],
["var", "density"],
1,
"#000000",
100,
"#ffffff"
]
],
"propertySpec": {
"type": "color"
},
"description": "let should preserve expected type for child expressions. If the expected 'color' type in this test were not preserved, it would not get passed into the interpolation and the literal strings wouldn't automatically coerce to the 'color' type",
"inputs": [[{}, {"properties": {"population": 100, "sq-km": 10}}]],
"expected": {
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "color"
},
"outputs": [
[0.09090909090909091,0.09090909090909091,0.09090909090909091,1]
],
"serialized": [
"let",
"density",
["/", ["number", ["get", "population"]], ["number", ["get", "sq-km"]]],
[
"interpolate",
["linear"],
["var", "density"],
1,
[
"rgba",
0,
0,
0,
1
],
100,
[
"rgba",
255,
255,
255,
1
]
]
]
}
}

0 comments on commit 395084c

Please sign in to comment.