Preserve function and final context in nested scopes

Currently checks for statements that are not allowed in functions or final
procedures only inspect the immediate scope. If the statement is inside a
named block or a block with declarations, the current scope is the block and
the context is lost.

Make `NetScope::in_func()` and `NetScope::in_final()` preserve the context
through begin-end, fork-join and generate block scopes. Other scope types are
treated as context boundaries so function and final state does not leak across
subroutine or definition scopes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-06-06 14:18:52 -07:00
parent c5c0b09ef6
commit 5b512e4f1e
2 changed files with 19 additions and 2 deletions

View File

@ -535,7 +535,24 @@ NetFuncDef* NetScope::func_def()
bool NetScope::in_func() const
{
return (type_ == FUNC) ? true : false;
if (type_ == FUNC)
return true;
if (type_ == BEGIN_END || type_ == FORK_JOIN || type_ == GENBLOCK)
return up_ ? up_->in_func() : false;
return false;
}
bool NetScope::in_final() const
{
if (in_final_)
return true;
if (type_ == BEGIN_END || type_ == FORK_JOIN || type_ == GENBLOCK)
return up_ ? up_->in_final() : false;
return false;
}
const NetFuncDef* NetScope::func_def() const

View File

@ -1193,7 +1193,7 @@ class NetScope : public Definitions, public Attrib {
/* Is this scope elaborating a final procedure? */
void in_final(bool in_final__) { in_final_ = in_final__; };
bool in_final() const { return in_final_; };
bool in_final() const;
const NetTaskDef* task_def() const;
const NetFuncDef* func_def() const;