Skip to content

Commit

Permalink
Fix error when work library has same name as entity. Fixes #991
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Sep 29, 2024
1 parent 41dbca6 commit aa11a9e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## Unreleased changes
- Fixed an error when using the `work` library alias and the working
library has the same name as design unit being analysed (#991).

## Version 1.14.0 - 2024-09-22
- Waiting on implicit `'stable` and `'quiet` signals now works
Expand Down
36 changes: 10 additions & 26 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1567,27 +1567,6 @@ static tree_t ensure_labelled(tree_t t, ident_t label)
return t;
}

static tree_t external_reference(tree_t t)
{
switch (tree_kind(t)) {
case T_ENTITY:
case T_LIBRARY:
case T_ARCH:
case T_PACKAGE:
case T_PACK_INST:
case T_CONFIGURATION:
{
tree_t ref = tree_new(T_REF);
tree_set_loc(ref, CURRENT_LOC);
tree_set_ident(ref, tree_ident(t));
tree_set_ref(ref, t);
return ref;
}
default:
return t;
}
}

static tree_t select_decl(tree_t prefix, ident_t suffix, name_mask_t *mask)
{
ident_t qual = ident_prefix(tree_ident(prefix), suffix, '.');
Expand Down Expand Up @@ -3488,8 +3467,6 @@ static tree_t p_attribute_name(tree_t prefix)
type = tree_type(prefix);
}

prefix = external_reference(prefix);

tree_t t = tree_new(T_ATTR_REF);
tree_set_name(t, prefix);

Expand Down Expand Up @@ -3570,7 +3547,7 @@ static tree_t p_selected_name(tree_t prefix, name_mask_t *mask)
tree_t decl = tree_ref(prefix);
const tree_kind_t kind = tree_kind(decl);
if (kind == T_LIBRARY) {
ident_t unit_name = ident_prefix(tree_ident(decl), suffix, '.');
ident_t unit_name = ident_prefix(tree_ident(prefix), suffix, '.');
tree_t unit = resolve_name(nametab, CURRENT_LOC, unit_name);
if (unit == NULL) {
tree_t dummy = tree_new(T_REF);
Expand All @@ -3579,8 +3556,15 @@ static tree_t p_selected_name(tree_t prefix, name_mask_t *mask)
*mask |= N_ERROR;
return dummy;
}
else
return external_reference(unit);
else {
assert(is_design_unit(unit));

tree_t ref = tree_new(T_REF);
tree_set_loc(ref, CURRENT_LOC);
tree_set_ident(ref, unit_name);
tree_set_ref(ref, unit);
return ref;
}
}
else if (kind == T_GENERIC_DECL && tree_class(decl) == C_PACKAGE)
return select_decl(tree_value(decl), suffix, mask);
Expand Down
13 changes: 13 additions & 0 deletions test/parse/issue991.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pack is
type t_enum is (a, b, c);
end package;

-------------------------------------------------------------------------------

entity issue991 is
end entity;

architecture test of issue991 is
constant c : work.pack.t_enum := work.pack.a; -- OK
begin
end architecture;
13 changes: 13 additions & 0 deletions test/test_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6897,6 +6897,18 @@ START_TEST(test_issue977)
}
END_TEST

START_TEST(test_issue991)
{
input_from_file(TESTDIR "/parse/issue991.vhd");

parse_and_check(T_PACKAGE, T_ENTITY, T_ARCH);

fail_unless(parse() == NULL);

fail_if_errors();
}
END_TEST

Suite *get_parse_tests(void)
{
Suite *s = suite_create("parse");
Expand Down Expand Up @@ -7060,6 +7072,7 @@ Suite *get_parse_tests(void)
tcase_add_test(tc_core, test_issue956);
tcase_add_test(tc_core, test_issue961);
tcase_add_test(tc_core, test_issue977);
tcase_add_test(tc_core, test_issue991);
suite_add_tcase(s, tc_core);

return s;
Expand Down

0 comments on commit aa11a9e

Please sign in to comment.