Skip to content

p4test fails for ArrayIndex expressions with non-constant indices #3374

Closed
@usha1830

Description

p4test fails when ArrayIndex expressions with non-constant different indices occur on both sides of assignment and when such an expression occurs as Switch expression.

The following statements fail to compile with p4test. Is this expected?

1) hdrs.vlan_tag[meta.depth].vid = hdrs.vlan_tag[meta.depth-1].vid;//  line 97 in attached program

// replacing one side array index with constant works fine

2) switch (hdrs.vlan_tag[meta.depth].vid)   // line 129 in attached program

 // replacing meta.depth with constant works fine

The error is :
pna-example-varIndex.p4(98): [--Werror=type-error] error: AssignmentStatement
hdrs.vlan_tag[meta.depth].vid = hdrs.vlan_tag[meta.depth-1].vid;
^^^^^^^^^^^^^^^^^^^^^^^^^^^
---- Actual error:
Cannot unify type 'bit<16>' with type 'bit<12>'
---- Originating from:
pna-example-varIndex.p4(94): Source expression 'hsVar_1' produces a result of type 'bit<16>' which cannot be assigned to a left-value with type 'bit<12>'
meta.ethType = hdrs.vlan_tag[meta.depth - 1].ether_type;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pna-example-varIndex.p4(130): [--Werror=type-error] error: AssignmentStatement
switch (hdrs.vlan_tag[meta.depth].vid) {
^^^^^^^^^^^^^^^^^^^^^^^^^
---- Actual error:
Cannot unify type 'Unknown type' with type 'bit<12>'
---- Originating from:
pna-example-varIndex.p4(130): Source expression 'hsVar' produces a result of type 'Unknown type' which cannot be assigned to a left-value with type 'bit<12>'
switch (hdrs.vlan_tag[meta.depth].vid) {

Example P4 program is attached.
hsindex.p4.txt

Metadata

Assignees

Labels

bugThis behavior is unintended and should be fixed.fixedThis topic is considered to be fixed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions