diff --git a/pform.cc b/pform.cc index 202939518..1df50f2c5 100644 --- a/pform.cc +++ b/pform.cc @@ -2338,7 +2338,22 @@ void pform_make_modgates(const struct vlltype&loc, struct parmvalue_t*overrides, svector*gates) { + // The grammer should not allow module gates to happen outside + // an active module. But if really bad input errors combine in + // an ugly way with error recovery, then catch this + // implausible situation and return an error. + if (pform_cur_module.empty()) { + cerr << loc << ": internal error: " + << "Module instantiations outside module scope are not possible." + << endl; + error_count += 1; + delete gates; + return; + } assert(! pform_cur_module.empty()); + + // Detect some more realistic errors. + if (pform_cur_module.front()->program_block) { cerr << loc << ": error: Module instantiations are not allowed in " << "program blocks." << endl;