Исправлена проверка типов в функции foreach

This commit is contained in:
Victor 2016-01-09 15:06:25 +02:00
parent 1f1a5ed7f0
commit 1fd2dd8e87

View File

@ -10,17 +10,17 @@ public final class std_foreach implements Function {
public Value execute(Value... args) { public Value execute(Value... args) {
if (args.length != 2) return NumberValue.ZERO; if (args.length != 2) return NumberValue.ZERO;
if (!(args[1] instanceof FunctionValue)) return NumberValue.ZERO; if (args[1].type() != Types.FUNCTION) return NumberValue.ZERO;
final Function function = ((FunctionValue) args[1]).getValue(); final Function function = ((FunctionValue) args[1]).getValue();
final Value container = args[0]; final Value container = args[0];
if (container instanceof ArrayValue) { if (container.type() == Types.ARRAY) {
final ArrayValue array = (ArrayValue) container; final ArrayValue array = (ArrayValue) container;
for (Value element : array) { for (Value element : array) {
function.execute(element); function.execute(element);
} }
return NumberValue.ZERO; return NumberValue.ZERO;
} }
if (container instanceof MapValue) { if (container.type() == Types.MAP) {
final MapValue map = (MapValue) container; final MapValue map = (MapValue) container;
for (Map.Entry<Value, Value> element : map) { for (Map.Entry<Value, Value> element : map) {
function.execute(element.getKey(), element.getValue()); function.execute(element.getKey(), element.getValue());