Additional null checks in Get and Call
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
This commit is contained in:
parent
d020f56414
commit
d417d1e581
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue