diff --git a/src/style-spec/expression/definitions/let.js b/src/style-spec/expression/definitions/let.js index 5eca64bff9a..b4334bfdc51 100644 --- a/src/style-spec/expression/definitions/let.js +++ b/src/style-spec/expression/definitions/let.js @@ -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); diff --git a/test/integration/expression-tests/let/expected-value/test.json b/test/integration/expression-tests/let/expected-value/test.json new file mode 100644 index 00000000000..157652e8d17 --- /dev/null +++ b/test/integration/expression-tests/let/expected-value/test.json @@ -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 + ] + ] + ] + } +}