Draft
Conversation
asl
reviewed
Dec 1, 2025
| } | ||
| } else { | ||
| // switch (expression) | ||
| if (!(type->is<IR::Type_Bits>() || type->is<IR::Type_InfInt>() || |
Contributor
There was a problem hiding this comment.
What's about typedefs and type aliases? Are they already resolved here?
Contributor
There was a problem hiding this comment.
Not sure if we have any test cases that cover that. Also of potential concern is a Type_Variable (where the type may not have been inferenced yet). Best would be to add test cases to cover all of those.
3e478ed to
5abda23
Compare
This was
linked to
issues
Dec 1, 2025
Signed-off-by: Mathew Suresh Zachariah <mazachar@pensando.io>
ChrisDodd
reviewed
Jan 24, 2026
| control C(out bit<8> y) { | ||
| action foo() { | ||
| // Here T is instantiated as bit<2>, so switch(v) is on bit<2>. | ||
| bar_generic<bit<2>>(1, y); |
Contributor
There was a problem hiding this comment.
This would seem to be ok/correct, but is still being flagged as an error.
|
|
||
| void bar(bit<2> x, out bit<8> y) { | ||
| TwoBitsAlias a = (TwoBitsAlias)x; | ||
| switch (a) { |
Contributor
There was a problem hiding this comment.
This too should be ok, not an error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to add a type check for generalized switch statements so that the switch expression is only allowed to be bit<W>, int<W>, enum (with or without an underlying type), or error, matching P4-16 spec https://p4.org/wp-content/uploads/sites/53/2024/10/P4-16-spec-v1.2.5.html#sec-switch-stmt