Skip to content

Disallow default parameters in parser/control type declarations#5687

Open
Sanketjadhav31 wants to merge 4 commits into
p4lang:mainfrom
Sanketjadhav31:disallow-default-parameters-parser-control-clean
Open

Disallow default parameters in parser/control type declarations#5687
Sanketjadhav31 wants to merge 4 commits into
p4lang:mainfrom
Sanketjadhav31:disallow-default-parameters-parser-control-clean

Conversation

@Sanketjadhav31

@Sanketjadhav31 Sanketjadhav31 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #5685

Summary

Disallow default parameter values in parser and control type declarations.

The frontend now reports a type error when a parser or control type declaration contains an apply parameter with a default value.

The existing control type test is moved from p4_16_samples to p4_16_errors, and a parser type regression test is added. Ordinary parser and control declarations with default parameters remain valid.

Tests

  • ctest -R "err.*default-control-argument" --output-on-failure
  • ctest -R "err.*issue5685-parser-default" --output-on-failure
  • ctest -R "p4.*issue1333" --output-on-failure
  • git diff HEAD --check

Signed-off-by: Sanketjadhav31 <sj546400@gmail.com>
Signed-off-by: Sanketjadhav31 <sj546400@gmail.com>
Signed-off-by: Sanketjadhav31 <sj546400@gmail.com>
Signed-off-by: Sanketjadhav31 <sj546400@gmail.com>
@fruffy fruffy added core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). labels Jul 7, 2026
@fruffy fruffy requested a review from ChrisDodd July 7, 2026 01:26
@ChrisDodd

Copy link
Copy Markdown
Contributor

This doesn't really "disallow" control/parser types with default args as such -- it flags an error if you ever try to call something (a package, generally, as only packages can have control/parser types as args) that uses control/parser type with a default arg. You can still declare such types, and declare packages that take them as args, as long as you never try to instantiate said package. This may be good enough -- actually trying to flag an error when the control/parser type is created would also flag errors for simple controls and parsers that have default args (which should be ok).

@fruffy @jafingerhut any opinion as to whether this is an acceptable approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Topics concerning the core segments of the compiler (frontend, midend, parser) p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disallowing default parameters in parser/control type declarations

3 participants