Esempio n. 1
0
 public string VisitReturnStmt(Stmt.ReturnStmt stmt)
 {
     if (stmt.Value == null)
     {
         return("(return)");
     }
     return(Parenthesize("return", stmt.Value));
 }
Esempio n. 2
0
        public object VisitReturnStmt(Stmt.ReturnStmt stmt)
        {
            if (_currentFunction == FunctionType.NONE)
            {
                Lox.Error(stmt.Keyword, "Cannot return from top-level code.");
            }
            if (stmt.Value != null)
            {
                if (_currentFunction == FunctionType.INITIALIZER)
                {
                    Lox.Error(stmt.Keyword, "Cannot return a value from an initializer.");
                }

                Resolve(stmt.Value);
            }
            return(null);
        }