Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow interpolation for variable-length numeric arrays #5519

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/style-spec/expression/definitions/curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ class Curve implements Expression {
if (interpolation.name !== 'step' &&
outputType.kind !== 'number' &&
outputType.kind !== 'color' &&
!(outputType.kind === 'array' && outputType.itemType.kind === 'number')) {
!(
outputType.kind === 'array' &&
outputType.itemType.kind === 'number' &&
typeof outputType.N === 'number'
)
) {
return context.error(`Type ${toString(outputType)} is not interpolatable, and thus cannot be used as a ${interpolation.name} curve's output type.`);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"expression": [
"curve",
["exponential", 2],
["number", ["get", "x"]],
1,
["array", "number", ["get", "array"]],
3,
["array", "number", ["get", "array_two"]]
],
"inputs": [],
"expected": {
"compiled": {
"result": "error",
"errors": [
{
"key": "",
"error": "Type array<number> is not interpolatable, and thus cannot be used as a exponential curve's output type."
}
]
}
}
}
21 changes: 21 additions & 0 deletions test/unit/style-spec/expression.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const test = require('mapbox-gl-js-test').test;
const {createExpression} = require('../../../src/style-spec/expression');

test('createExpression', (t) => {
test('require piecewise-constant zoom curves to use "step" interpolation', (t) => {
const expression = createExpression([
'curve', ['linear'], ['zoom'], 0, 0, 10, 10
], {
type: 'number',
function: 'piecewise-constant'
});
t.equal(expression.result, 'error');
t.equal(expression.errors.length, 1);
t.equal(expression.errors[0].message, 'interpolation type must be "step" for this property');
t.end();
});

t.end();
});
2 changes: 1 addition & 1 deletion test/unit/style-spec/fixture/functions.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"line": 934
},
{
"message": "layers[52].paint.line-dasharray: interpolation type must be \"step\" for this property",
"message": "layers[52].paint.line-dasharray: Type array<number> is not interpolatable, and thus cannot be used as a linear curve's output type.",
"line": 943
}
]