visitUnaryExpr method

  1. @override
Object? visitUnaryExpr(
  1. Unary expr
)
override

Implementation

@override
Object? visitUnaryExpr(Expr.Unary expr) {
  Object? right = evaluate(expr.right);

  switch (expr.operator.type) {
    case TokenType.BANG:
      return !isTruthy(right);
    case TokenType.MINUS:
      checkNumberOperand(expr.operator, right);
      return -(right as num);
  }

  return null;
}