diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index 171bd80712e39f24fde1b60619301c07134baae0..32e5f32881f5ed7339cca084e96e752a079be4d4 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -142,6 +142,10 @@ DynamicModel::operator=(const DynamicModel &m)
 void
 DynamicModel::writeDynamicBytecode(const string &basename) const
 {
+  /* Bytecode only works when there are with as many endogenous as equations.
+     (e.g. the constructor of FBEGINBLOCK_ makes this assumption) */
+  assert(static_cast<int>(equations.size()) == symbol_table.endo_nbr());
+
   // Determine the type of model (used for typing the single block)
   BlockSimulationType simulation_type;
   if (max_endo_lag > 0 && max_endo_lead > 0)
diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc
index d2a0c1d804a1044a801882a9cd9ea508b016293a..120847977cf35b7ff363dea66ae0494d0b65e386 100644
--- a/src/ModelEquationBlock.cc
+++ b/src/ModelEquationBlock.cc
@@ -37,6 +37,12 @@ PlannerObjective::computingPassBlock([[maybe_unused]] const eval_context_t &eval
   // Disable block decomposition on planner objective
 }
 
+void
+PlannerObjective::writeStaticBytecode([[maybe_unused]] const string &basename) const
+{
+  // Disable bytecode output, because there are not as many variables as equations
+}
+
 OrigRamseyDynamicModel::OrigRamseyDynamicModel(SymbolTable &symbol_table_arg,
                                                NumericalConstants &num_constants_arg,
                                                ExternalFunctionsTable &external_functions_table_arg,
diff --git a/src/ModelEquationBlock.hh b/src/ModelEquationBlock.hh
index 8efe6aaf7aa24f98132b7e7afe7416bd04ece960..9f8536d436e307997dd2044191d3f1af134f316c 100644
--- a/src/ModelEquationBlock.hh
+++ b/src/ModelEquationBlock.hh
@@ -41,6 +41,7 @@ protected:
 
 private:
   void computingPassBlock(const eval_context_t &eval_context, bool no_tmp_terms) override;
+  void writeStaticBytecode(const string &basename) const override;
 };
 
 class OrigRamseyDynamicModel : public DynamicModel
diff --git a/src/StaticModel.cc b/src/StaticModel.cc
index fb15c88140eea5d3043b141414b20a5060086a98..6760a4925cb6742956e6997cf16fb5ca4d763f23 100644
--- a/src/StaticModel.cc
+++ b/src/StaticModel.cc
@@ -102,6 +102,10 @@ StaticModel::StaticModel(const DynamicModel &m) :
 void
 StaticModel::writeStaticBytecode(const string &basename) const
 {
+  /* Bytecode only works when there are with as many endogenous as equations.
+     (e.g. the constructor of FBEGINBLOCK_ makes this assumption) */
+  assert(static_cast<int>(equations.size()) == symbol_table.endo_nbr());
+
   // First write the .bin file
   int u_count_int { writeBytecodeBinFile(basename + "/model/bytecode/static.bin", false) };
 
diff --git a/src/StaticModel.hh b/src/StaticModel.hh
index 5e98f28f0db2b67e6b901ef19dd62df7d142e049..8df4d084abd3569ac13f1025f30a9234167c9e71 100644
--- a/src/StaticModel.hh
+++ b/src/StaticModel.hh
@@ -60,7 +60,7 @@ private:
   void writeStaticBlockBytecode(const string &basename) const;
 
   //! Writes the code of the model in virtual machine bytecode
-  void writeStaticBytecode(const string &basename) const;
+  virtual void writeStaticBytecode(const string &basename) const;
 
   //! Computes jacobian and prepares for equation normalization
   /*! Using values from initval/endval blocks and parameter initializations: