Improve error reporting around function calls with incorrect arity
This commit is contained in:
parent
be5abb3bdc
commit
67ddce9ab6
@ -485,7 +485,7 @@ carto.Parser = function Parser(env) {
|
||||
|
||||
if (! $(')')) return;
|
||||
|
||||
if (name) { return new tree.Call(name, args) }
|
||||
if (name) { return new tree.Call(name, args, i) }
|
||||
},
|
||||
arguments: function() {
|
||||
var args = [], arg;
|
||||
|
@ -3,9 +3,10 @@
|
||||
//
|
||||
// A function call node.
|
||||
//
|
||||
tree.Call = function Call(name, args) {
|
||||
tree.Call = function Call(name, args, index) {
|
||||
this.name = name;
|
||||
this.args = args;
|
||||
this.index = index;
|
||||
};
|
||||
tree.Call.prototype = {
|
||||
//
|
||||
@ -33,7 +34,21 @@ tree.Call.prototype = {
|
||||
}
|
||||
|
||||
if (this.name in tree.functions) { // 1.
|
||||
return tree.functions[this.name].apply(tree.functions, args);
|
||||
if (tree.functions[this.name].length === args.length) {
|
||||
return tree.functions[this.name].apply(tree.functions, args);
|
||||
} else {
|
||||
env.error({
|
||||
message: 'incorrect number of arguments for ' + this.name +
|
||||
'(). ' + tree.functions[this.name].length + ' expected.',
|
||||
index: this.index,
|
||||
type: 'runtime',
|
||||
filename: this.filename
|
||||
});
|
||||
return {
|
||||
is: 'undefined',
|
||||
value: 'undefined'
|
||||
};
|
||||
}
|
||||
} else { // 2.
|
||||
return new tree.Anonymous(this.name +
|
||||
'(' + args.map(function(a) { return a.toString(); }).join(', ') + ')');
|
||||
|
Loading…
Reference in New Issue
Block a user