p4c icon indicating copy to clipboard operation
p4c copied to clipboard

switch allowing duplicated cases for switch on bit<4>

Open apinski-cavium opened this issue 3 years ago • 0 comments

Take:

#include <core.p4>

control c(in bit<4> a)
{
  apply {
    switch (a) {
      4w0: {}
      4w1: {} // { dg-note "" }
      4w1: {} // { dg-error "" }
    }
  }
}

control ct(in bit<4> a);
package pt(ct t);
pt(c()) main;

This should fail as 4w1 is repeated. The langauge spec is clear here even:

12.7.3. Notes common to all switch statements
It is a compile-time error if two labels of a switch statement equal each other. 

apinski-cavium avatar Oct 24 '22 19:10 apinski-cavium