-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow implicit casts in switch labels; improve error message #3634
Conversation
Fixes #3623 |
@@ -3836,6 +3836,8 @@ const IR::Node* TypeInference::postorder(IR::SwitchStatement* stat) { | |||
auto lt = getType(c->label); | |||
if (lt == nullptr) | |||
continue; | |||
if (auto se = lt->to<IR::Type_SerEnum>()) | |||
lt = se->type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure with this change but will the following still work:
enum bit<4> e
{
a = 1
}
control c(in e v)
{
apply{
switch(v) {
e.a:
default: {}
}
}
}
and will this still be rejected:
enum bit<4> e
{
a = 1
}
control c(in e v)
{
apply{
switch(v) {
1:
default: {}
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added theses test cases.
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
@@ -0,0 +1,6 @@ | |||
issue3623-2.p4(8): [--Werror=type-error] error: 'v' with type 'e' cannot be compared to '4w1' with type 'bit<4>' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message are a little vague. Any way to make it more clear that this concerns a (ser)enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing 'toString' will show better error messages. Just pushed this change.
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
Signed-off-by: Mihai Budiu mbudiu@vmware.com