Inside my package, I have been careful to try to create indices that are legal for the actual generic type mapped to ArrayType. However, I have noticed a curiosity and I am wondering why it is not failing.
Lets return to ArrayGenericUsagePkg from #1478
If I declare the variable A as follows:
variable A : ArrayType(-1 to IndexType(Size - 2)) := (others => iValue) ;
Although -1 is outside of the allowed indexed range for the arrays mapped in the package instance. However, the testbench runs fine and produces the expected results. Is there something that allows this?
library ieee ;
use ieee.std_logic_1164.all ;
package ArrayGenericUsagePkg is
generic (type ArrayType is array (type is range <>) of type is private ) ;
subtype ElementType is ArrayType'element ;
subtype IndexType is ArrayType'index ;
function CreateArray(Size : integer ; iValue : ArrayType'element) return ArrayType ;
end package ArrayGenericUsagePkg ;
package body ArrayGenericUsagePkg is
function CreateArray(Size : integer ; iValue : ArrayType'element) return ArrayType is
-- NVC: Works. Why? -1 is not a legal value of IndexType!! which is natural
variable A : ArrayType(-1 to IndexType(Size - 2)) := (others => iValue) ;
begin
return A ;
end function CreateArray ;
end package body ArrayGenericUsagePkg ;
Package Instance: ArrayUsagePkg_IntV
package ArrayUsagePkg_IntV is new work.ArrayGenericUsagePkg
generic map (ArrayType => integer_vector ) ;
library ieee ;
use ieee.std_logic_1164.all ;
package ArrayUsagePkg_slv is new work.ArrayGenericUsagePkg
generic map (ArrayType => std_logic_vector ) ;
Test Case: test.vhd
use work.ArrayUsagePkg_IntV.all ;
entity test is
end entity test ;
architecture a of test is
signal A : integer_vector(0 to 5) := CreateArray(6, 1) ;
signal B : integer_vector(0 to 2) ;
begin
P1: process
begin
B <= CreateArray(3, 2) ;
wait for 5 ns ;
report "A: " & to_string(A) severity note ;
report "B: " & to_string(B) severity note ;
std.env.stop ;
wait ;
end process ;
end architecture a ;
OTOH, if I try type integer for the index range, NVC correctly flags this as an error since the type of Size is integer:
variable A : ArrayType(0 to Size-1) := (others => iValue) ;
I could see the language considering this erroneous since it is hard to detect. It cannot be checked before the package instance.
Inside my package, I have been careful to try to create indices that are legal for the actual generic type mapped to ArrayType. However, I have noticed a curiosity and I am wondering why it is not failing.
Lets return to ArrayGenericUsagePkg from #1478
If I declare the variable A as follows:
variable A : ArrayType(-1 to IndexType(Size - 2)) := (others => iValue) ;Although
-1is outside of the allowed indexed range for the arrays mapped in the package instance. However, the testbench runs fine and produces the expected results. Is there something that allows this?Package Instance: ArrayUsagePkg_IntV
Test Case: test.vhd
OTOH, if I try type integer for the index range, NVC correctly flags this as an error since the type of Size is integer:
variable A : ArrayType(0 to Size-1) := (others => iValue) ;I could see the language considering this erroneous since it is hard to detect. It cannot be checked before the package instance.