Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matching case? allows multiple arms with the same pattern #966

Closed
nathanaelhuffman opened this issue Sep 6, 2024 · 1 comment
Closed

Comments

@nathanaelhuffman
Copy link

This is accepted by nvc and runs, I believe this should be compile error, otherwise I'm not sure what the return value would be expected to be.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

package pack is
    function matching_cases (
        opcode: std_logic_vector
    ) return natural;
   
end package;

package body pack is

    function matching_cases (
        opcode: std_logic_vector
    ) return natural is

        variable bytes : natural := 0;

    begin
        case? opcode is
            when "00000000" =>
                bytes := 1;
            when "00000001" =>
                bytes := 1;
            when "010000--" =>
                bytes := 1;
            when "010000--" =>  -- SAME CONDITION AS ABOVE ARM!!!
                bytes := 2; -
            when others =>
                bytes := 4; 
        end case?;
        return bytes;
    end;

end package body;
@nickg nickg closed this as completed in af2dd6b Sep 7, 2024
@nickg
Copy link
Owner

nickg commented Sep 7, 2024

Bounds checks were missing for case? statements. Now it reports:

** Error: duplicate choice in case statement
    > ../test/bounds/issue966.vhd:27
    |
 25 |             when "010000--" =>
    |                  ^^^^^^^^^^ previous choice for this value
 26 |                 bytes := 1;
 27 |             when "010000--" =>  -- SAME CONDITION AS ABOVE ARM!!!
    |                  ^^^^^^^^^^ repeated here
    |
    = Note: each value of the subtype of the expression must be represented once and only 
            once in the set of choices
    = Help: IEEE Std 1076-2008 section 10.9 "Case statement"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants