8000 Fails to reject `isValid` method call with arguments or type arguments, on constant header value · Issue #5299 · p4lang/p4c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Fails to reject isValid method call with arguments or type arguments, on constant header value #5299
Open
@jaehyun1ee

Description

@jaehyun1ee

The built-in method isValid should not take any argument or type argument. This check works in P4C, e.g.,

extern void sink(in bool b);

header Hdr { bit<32> x; }

control C(in Hdr hdr);
package P(C c);

control CImpl(in Hdr hdr) {
   apply { sink(hdr.isValid(1w1)); }
}
P(CImpl()) main;

fails as expected:

3-is-valid-rep-well.p4(9): [--Werror=type-error] error: 'hdr.isValid(1w1)'
   apply { sink(hdr.isValid(1w1)); }
                ^^^^^^^^^^^^^^^^
  ---- Actual error:
  isValid: 1 arguments supplied while 0 are expected
  ---- Originating from:
  3-is-valid-rep-well.p4(9): Function type 'isValid' does not match invocation type '<Method call>'
     apply { sink(hdr.isValid(1w1)); }
                  ^^^^^^^^^^^^^^^^

However, when isValid is called on a constant value, seems like type inference or constant folding pass accepts isValid call with arguments or type arguments as valid.

header h {}
bool f() {
  return ((h) { }).isValid(_);
}

control C();
package P(C c);

control CImpl() { apply { f(); } }
P(CImpl()) main;

The above program is accepted by p4test. Running with --top4 to inspect each pass, at -0017-FrontEnd_12_TypeInference.p4, the function f becomes:

bool f() {
    return true;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    p4-specTopics related to the P4 specification (https://github.com/p4lang/p4-spec/).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0