jeremiah-c-leary / vhdl-style-guide

Style guide enforcement for VHDL
GNU General Public License v3.0
192 stars 39 forks source link

variable_assignment_401 conflicts with variable_assignment_004 #1295

Open maltaisn opened 4 weeks ago

maltaisn commented 4 weeks ago

For the following file:

library ieee;
  use ieee.std_logic_1164.all;

package body mypackage is

  type foo is record
    a : natural;
    b : natural;
    c : natural;
  end record foo;

  type natural_array is array (natural range <>) of natural;

  function bar (
    f : foo
  ) return natural_array is

    variable value : natural_array;

  begin

    value :=
    (
      0 => f.a,
      1 => f.b,
      2 => f.c
    );
    return value;

  end function bar;

end package body mypackage;

I get the following errors with the default configuration:

variable_assignment_004   | Error      |         23 | Indent with 13 space(s)
variable_assignment_004   | Error      |         24 | Indent with 14 space(s)
variable_assignment_004   | Error      |         25 | Indent with 14 space(s)
variable_assignment_004   | Error      |         26 | Indent with 14 space(s)
variable_assignment_004   | Error      |         27 | Indent with 12 space(s)

The errors are fixed if either variable_assignment_401 or variable_assignment_004 is disabled.

JHertz5 commented 3 weeks ago

Hi @maltaisn. Thanks for raising this. I have also experienced this issue. I'll try to take a look soon.

JHertz5 commented 1 week ago

Hi @maltaisn.

I've figured out the problem. variable_assignment_004 should not be acting here, this case should be covered by variable_assignment_401 which is designed to act on arrays. The "parent rule" for variable_assignment_004 has a check which should skip the rule when it detects that it is acting on an array assignment (since it is assumed that there will be a separate rule to handle the array assignment). However, this check was coded to check only for signal assignment operators (<=).

    return utils.are_next_consecutive_tokens_ignoring_whitespace(["<=", "("], 0, oToi.get_tokens())

Since variable assignments use a different assignment operator, the check that should be skipping them does not skip them. I've raised a PR (#1313) to correct the issue. If you have a chance, please check the branch https://github.com/JHertz5/vhdl-style-guide/tree/issue-1295 and confirm that the fix works for you.

maltaisn commented 1 week ago

It works for the example I gave, thanks.