public void VisitReturnStmt(ReturnStmt stmt) { object value = null; if (stmt.Value != null) { value = Evaluate(stmt.Value); } throw new Return(value); }
public void VisitReturnStmt(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); } }