Browse files

Checking for slices/references of array subtypes

  • Loading branch information...
1 parent ab3d946 commit 2bddd878ab4c21c3af5db9066c36ed44134c5bb2 @nickg committed Mar 24, 2012
Showing with 17 additions and 1 deletion.
  1. +7 −1 src/sem.c
  2. +9 −0 test/sem/array.vhd
  3. +1 −0 test/test_sem.c
View
8 src/sem.c
@@ -2792,8 +2792,11 @@ static bool sem_check_array_ref(tree_t t)
if (!sem_check(value))
return false;
+ type_t type = tree_type(tree_value(t));
+ while (type_kind(type) == T_SUBTYPE)
+ type = type_base(type);
+
unsigned nindex;
- type_t type = tree_type(value);
switch (type_kind(type)) {
case T_CARRAY:
nindex = type_dims(type);
@@ -2841,6 +2844,9 @@ static bool sem_check_array_slice(tree_t t)
return false;
type_t array_type = tree_type(tree_value(t));
+ while (type_kind(array_type) == T_SUBTYPE)
+ array_type = type_base(array_type);
+
type_kind_t array_k = type_kind(array_type);
if (array_k != T_CARRAY && array_k != T_UARRAY)
View
9 test/sem/array.vhd
@@ -120,5 +120,14 @@ begin
y(1 to 3) := (others => 4); -- Error
assert y = (others => 4); -- Error
end process;
+
+ process is
+ subtype five_ints is ten_ints(1 to 4);
+ variable x : five_ints;
+ begin
+ x(1 to 3) := (1, 2, 3); -- OK
+ x(2) := 1; -- OK
+ x(3 downto 1) := (others => '0'); -- Error
+ end process;
end architecture;
View
1 test/test_sem.c
@@ -496,6 +496,7 @@ START_TEST(test_array)
{ 119, "type of slice prefix is not an array" },
{ 120, "range direction of slice does not match prefix" },
{ 121, "others choice not allowed in this context" },
+ { 130, "range direction of slice does not match prefix" },
{ -1, NULL }
};
expect_errors(expect);

0 comments on commit 2bddd87

Please sign in to comment.