Skip to content
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

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

mihaibudiu
Copy link
Contributor

Signed-off-by: Mihai Budiu mbudiu@vmware.com

@mihaibudiu
Copy link
Contributor Author

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;

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: {}
    }
  }
}

Copy link
Contributor Author

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>'
Copy link
Collaborator

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?

Copy link
Contributor Author

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>
@mihaibudiu mihaibudiu merged commit 97cffff into p4lang:main Nov 2, 2022
@mihaibudiu mihaibudiu deleted the issue3623 branch November 2, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants