evaluateCases method
Implementation
EvaluateExprOutput evaluateCases(EvaluateExprInput input) {
final cases = input.expr.obj["cases"]!;
for (final (pos, c) in cases.arr.indexed) {
final path = pathAppendIndex(pathAppendKey(input.path, "cases"), pos);
if (c.obj.containsKey("when")) {
final when = evaluateExpr(EvaluateExprInput(
path: pathAppendKey(path, "when"),
defs: input.defs,
expr: c.obj["when"]));
if (when.status != EvaluateExprOutput_Status.OK) {
return when;
}
if (when.value.type != Type.TYPE_BOOL) {
return _errorUnexpectedType(
pathAppendKey(path, "when"), [Type.TYPE_BOOL], when.value.type);
}
if (when.value.bool_2) {
final then = evaluateExpr(EvaluateExprInput(
path: pathAppendKey(path, "then"),
defs: input.defs,
expr: c.obj["then"]));
if (then.status != EvaluateExprOutput_Status.OK) {
return then;
}
return then;
}
} else if (c.obj.containsKey("otherwise")) {
final otherwise = evaluateExpr(EvaluateExprInput(
path: pathAppendKey(path, "otherwise"),
defs: input.defs,
expr: c.obj["otherwise"]));
if (otherwise.status != EvaluateExprOutput_Status.OK) {
return otherwise;
}
return otherwise;
}
}
return _errorCasesNotExhaustive(pathAppendKey(input.path, "cases"));
}