From 29836b846fb067893186deb6932d9a3b7ea3aadc Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 15 Jan 2024 22:11:12 +0000 Subject: [PATCH] Improve error message with OPEN in generic map --- src/elab.c | 3 +++ test/elab/bounds11.vhd | 37 +++++++++++++++++++++++++++++++++++++ test/test_elab.c | 20 ++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 test/elab/bounds11.vhd diff --git a/src/elab.c b/src/elab.c index 3bc477da..607c1c9e 100644 --- a/src/elab.c +++ b/src/elab.c @@ -549,6 +549,9 @@ static void elab_write_generic(text_buf_t *tb, tree_t value) case T_TYPE_REF: tb_printf(tb, "%s", type_pp(tree_type(value))); break; + case T_OPEN: + tb_cat(tb, "OPEN"); + break; default: tb_printf(tb, "..."); DEBUG_ONLY(tb_cat(tb, tree_kind_str(tree_kind(value)))); diff --git a/test/elab/bounds11.vhd b/test/elab/bounds11.vhd new file mode 100644 index 00000000..3748ec06 --- /dev/null +++ b/test/elab/bounds11.vhd @@ -0,0 +1,37 @@ +package pack is + function get_value return integer; +end package; + +package body pack is + function get_value return integer is + begin + return 5; + end function; +end package body; + +------------------------------------------------------------------------------- + +use work.pack.all; + +entity sub is + generic ( G : integer := get_value ); + port ( x : bit_vector(1 to G) ); +end entity; + +architecture test of sub is +begin +end architecture; + +------------------------------------------------------------------------------- + +entity bounds11 is +end entity; + +architecture test of bounds11 is + signal s : bit_vector(1 to 3); +begin + + u: entity work.sub + port map ( s ); -- Error + +end architecture; diff --git a/test/test_elab.c b/test/test_elab.c index 983692a1..d61841d8 100644 --- a/test/test_elab.c +++ b/test/test_elab.c @@ -1717,6 +1717,25 @@ START_TEST(test_bounds7) } END_TEST +START_TEST(test_bounds11) +{ + input_from_file(TESTDIR "/elab/bounds11.vhd"); + + const error_t expect[] = { + { 35, "actual length 3 does not match formal length 5" }, + { 0, "while elaborating instance U" }, + { 0, "generic G => OPEN" }, + { -1, NULL } + }; + expect_errors(expect); + + tree_t e = run_elab(); + fail_unless(e == NULL); + + check_expected_errors(); +} +END_TEST + Suite *get_elab_tests(void) { Suite *s = suite_create("elab"); @@ -1811,6 +1830,7 @@ Suite *get_elab_tests(void) tcase_add_loop_test(tc, test_block2, STD_02, STD_19 + 1); tcase_add_test(tc, test_gentype1); tcase_add_test(tc, test_bounds7); + tcase_add_test(tc, test_bounds11); suite_add_tcase(s, tc); return s; -- 2.39.2