Additional null checks in Get and Call
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Johannes Frohnmeyer 2023-06-27 16:22:00 +02:00
parent d020f56414
commit d417d1e581
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 5 additions and 2 deletions

View File

@ -31,8 +31,9 @@ public class Call extends DynamicExpr {
DCallable dc;
DList arg;
try {
dc = left.get(dataRoot)
.asCallable();
Dynamic<?> lv = left.get(dataRoot);
if (lv == null || lv instanceof DNull) throw new LocationalException(location, "Cannot invoke null");
dc = lv.asCallable();
arg = DFinal.of(args.stream().flatMap(e -> e.get(dataRoot)).toArray(Dynamic[]::new));
} catch (DynamicTypeConversionException e) {
throw e.locational(location);

View File

@ -8,6 +8,7 @@ import io.gitlab.jfronny.muscript.ast.literal.StringLiteral;
import io.gitlab.jfronny.muscript.compiler.*;
import io.gitlab.jfronny.muscript.data.Scope;
import io.gitlab.jfronny.muscript.data.dynamic.*;
import io.gitlab.jfronny.muscript.error.LocationalException;
import io.gitlab.jfronny.muscript.error.TypeMismatchException;
import java.io.IOException;
@ -30,6 +31,7 @@ public class Get extends DynamicExpr {
@Override
public Dynamic<?> get(Scope dataRoot) {
Dynamic<?> left = this.left.get(dataRoot);
if (left == null || left instanceof DNull) throw new LocationalException(location, "Could not get \"" + name.asStringExpr().get(dataRoot) + "\" because left is null");
if (left instanceof DObject o) {
return o.get(name.asStringExpr().get(dataRoot));
} else if (left instanceof DList l) {