Skip to content

Commit

Permalink
Infer type assertions for object
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Feb 28, 2018
1 parent 5e9f458 commit 2feee52
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/style-spec/expression/parsing_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ParsingContext {
// When we expect a Color but have a String or Value, we
// can wrap it in "to-color" coercion.
// Otherwise, we do static type-checking.
if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean') && actual.kind === 'value') {
if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object') && actual.kind === 'value') {
if (!options.omitTypeAnnotations) {
parsed = new Assertion(expected, [parsed]);
}
Expand Down
20 changes: 20 additions & 0 deletions test/integration/expression-tests/object/implicit/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"expression": ["get", "b", ["get", "a"]],
"inputs": [
[{}, {"properties": {"a": {"b": 0}}}],
[{}, {"properties": {"a": "not"}}]
],
"expected": {
"compiled": {
"result": "success",
"isFeatureConstant": false,
"isZoomConstant": true,
"type": "value"
},
"outputs": [
0,
{"error": "Expected value to be of type object, but found string instead."}
],
"serialized": ["get", "b", ["get", "a"]]
}
}

0 comments on commit 2feee52

Please sign in to comment.