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

Implicit cast is allowed on types introduced by the type keyword when it shoudn't #5087

Open
jaehyun1ee opened this issue Jan 6, 2025 · 0 comments
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).

Comments

@jaehyun1ee
Copy link

Spec section 7.6. Introducing new types mentions that type introduced by the type keyword is not a synonym with its underlying type.

However, tests psa-dpdk-binary-operations-1.p4, psa-dpdk-binary-operations.p4, psa-dpdk-header-union-typedef.p4, pins_fabric.p4. pins_middleblock.p4, and pins_wbb.p4 expect that new types can be implicitly cast to their underlying types.

For example,

// psa-dpdk-binary-operations-1.p4

typedef bit<32>  PortIdUint_t;
type PortIdUint_t         PortId_t;
struct psa_ingress_input_metadata_t {
  PortId_t                 ingress_port;
  // ...
}

control MyIC(
    inout ethernet_t a,
    inout metadata b,
    in psa_ingress_input_metadata_t c,
    inout psa_ingress_output_metadata_t d) {
    bit<8> Op1 = 0x2;
    bit<16> Op2 = 0x23;
    action forward() {
        b.meta = 32w0x1 << c.ingress_port; // c.ingress_port is of type PortId_t, should use (bit<32>) c.ingress_port instead.
    }
    // ...
}
@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

No branches or pull requests

2 participants