diff --git a/elab_type.cc b/elab_type.cc index 42a13ed43..aeb8e5492 100644 --- a/elab_type.cc +++ b/elab_type.cc @@ -49,7 +49,20 @@ ivl_type_t data_type_t::elaborate_type(Design*des, NetScope*scope) if (pos != cache_type_elaborate_.end() && pos->first == use_definitions) return pos->second; - ivl_type_t tmp = elaborate_type_raw(des, scope); + ivl_type_t tmp; + if (elaborating) { + des->errors++; + cerr << get_fileline() << ": error: " + << "Circular type definition found involving `" << *this << "`." + << endl; + // Try to recover + tmp = netvector_t::integer_type(); + } else { + elaborating = true; + tmp = elaborate_type_raw(des, scope); + elaborating = false; + } + cache_type_elaborate_.insert(pos, pair(scope, tmp)); return tmp; } diff --git a/pform_types.h b/pform_types.h index 2b0d63779..509e1d5e2 100644 --- a/pform_types.h +++ b/pform_types.h @@ -167,6 +167,8 @@ class data_type_t : public PNamedItem { virtual ivl_type_t elaborate_type_raw(Design*des, NetScope*scope) const; virtual NetScope *find_scope(Design* des, NetScope *scope) const; + bool elaborating = false; + // Keep per-scope elaboration results cached. std::map cache_type_elaborate_; };