p4c icon indicating copy to clipboard operation
p4c copied to clipboard

instantation of parser inside functions error message could be clear

Open apinski-cavium opened this issue 3 years ago • 2 comments

Take:

parser p() {
    state start {
        transition accept;
    }
}

void func()
{
  p() t;
  t();
}

The reference compiler produces:

t8.p4(9): [--Werror=invalid] error: t: cannot instantiate at top-level
  p() t;
      ^

But a function is not the top-level.

Note a similar issue dealing with direct application to the type too:

t8.p4(9): [--Werror=not-found] error: p_inst: declaration not found
  p.apply();
  ^^^^^^^^^

It is not obvious what is wrong from the error message really.

The table in "Appendix: Restrictions on compile time and run time calls" does make it clear this is invalid code but the error message should be improved.

apinski-cavium avatar Apr 13 '22 02:04 apinski-cavium

I expect #3279 will fix this one too.

mihaibudiu avatar May 02 '22 23:05 mihaibudiu

@apinski-cavium Do you consider this issue fixed after #3279 was merged? If yes, please consider closing the issue.

jfingerh avatar Nov 19 '22 15:11 jfingerh