title: In SystemVerilog are indexing a parameter array in a for loop a constant expression
body: <p>The following modules tries to use an unpacked parameter array in three different ways.</p>
  
  <pre><code>module works
    #(parameter int num = 4,
      parameter int width = 8,
      parameter int bits [num] = '{4, 4})
     (output logic [width-1:0] mask [num]);
  
      genvar i;
      generate
          for(i=0; i&lt;num; ++i) begin
              always_comb mask[i] = {{(width-bits[i]){1'b0}},{bits[i]{1'b1}}};
          end
      endgenerate
  endmodule
  
  module also_works
    #(parameter int num = 4,
      parameter int width = 8,
      parameter int bits [num] = '{4, 4})
     (output logic [width-1:0] mask [num]);
  
      always_comb begin
          mask[0] = {{(width-bits[0]){1'b0}},{bits[0]{1'b1}}};
          mask[1] = {{(width-bits[1]){1'b0}},{bits[1]{1'b1}}};
          mask[2] = {{(width-bits[2]){1'b0}},{bits[2]{1'b1}}};
          mask[3] = {{(width-bits[3]){1'b0}},{bits[3]{1'b1}}};
      end
  endmodule
  
  module fails
    #(parameter int num = 4,
      parameter int width = 8,
      parameter int bits [num] = '{4, 4})
     (output logic [width-1:0] mask [num]);
  
      always_comb begin
          for(int i=0; i&lt;num; ++i) begin
              mask[i] = {{(width-bits[i]){1'b0}},{bits[i]{1'b1}}};
          end
      end
  endmodule
  </code></pre>
  
  <p>The first two modules are considered correct by the simulator I am using. However the last one is considered to not correct since <code>i</code> is not a constant expression. However the only way I can semantically interpret the for loop in the always block version is the same as <code>also_works</code>.</p>
  
  <p>I could not find anything in the standard that clarifies this situation, expect what is stated in Section 11.2.1</p>
  
  <blockquote>
    <p><strong>11.2.1 Constant expressions</strong></p>
    
    <p>Some statement constructs require an expression to be a constant
    expression. The operands of a constant expression consist of constant
    numbers, strings, parameters, constant bit-selects and part-selects of
    parameters, constant function calls (see 13.4.3), and constant system
    function calls only. Constant expressions can use any of the operators
    defined in Table 11-1.</p>
  </blockquote>
  
  <p>As far as I can see it only talks about bit and part-selects and not about indexing parameter arrays.</p>