mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Исправлена проверка типов в функции foreach
This commit is contained in:
parent
1f1a5ed7f0
commit
1fd2dd8e87
@ -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());
|
||||||
|
Loading…
Reference in New Issue
Block a user