Exemplo n.º 1
0
        public object VisitReturnStmt(Stmt.Return stmt)
        {
            object value = null;

            if (stmt.Value != null)
            {
                value = Evaluate(stmt.Value);
            }

            throw new Return(value);
        }
Exemplo n.º 2
0
 public object VisitReturnStmt(Stmt.Return stmt)
 {
     if (_currentFunction == FunctionType.NONE)
     {
         Lox.Error(stmt.Keyword, "Cannot return from top-level code.");
     }
     if (stmt.Value == null)
     {
         return(null);
     }
     if (_currentFunction == FunctionType.INITIALIZER)
     {
         Lox.Error(stmt.Keyword, "Cannot return a value from an initializer.");
     }
     Resolve(stmt.Value);
     return(null);
 }