From 7d793c6a781e318ed86e900adc51a10fb84938aa Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 8 Jul 2023 11:10:27 +0100 Subject: [PATCH] Add test for missing protected type method --- src/names.c | 40 ++++++++++------------------------------ src/rt/reflect.c | 4 ++-- test/parse/typo.vhd | 16 ++++++++++++++++ test/test_parse.c | 9 ++++++++- 4 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/names.c b/src/names.c index 156d4f53..dd77eceb 100644 --- a/src/names.c +++ b/src/names.c @@ -2232,7 +2232,6 @@ static void begin_overload_resolution(overload_t *o) if (o->initial == 0 && !o->error) { diag_t *d = diag_new(DIAG_ERROR, tree_loc(o->tree)); - diag_printf(d, "no visible subprogram declaration for %s", istr(o->name)); if (sym != NULL) { const bool hinted = diag_hints(d) > 0; @@ -2247,38 +2246,19 @@ static void begin_overload_resolution(overload_t *o) diag_hint(d, tree_loc(o->tree), "%s called here", istr(o->name)); } - if (o->prefix != NULL) { - type_t ptype = tree_type(o->prefix); - if (type_is_protected(ptype)) { - scope_t *s = scope_for_type(o->nametab, ptype); - hint_for_typo(s, d, o->name, N_SUBPROGRAM); - - LOCAL_TEXT_BUF tb = tb_new(); - int others = 0, methods = 0; - const int ndecls = type_decls(ptype); - for (int i = 0; i < ndecls; i++) { - tree_t d = type_decl(ptype, i); - if (is_subprogram(d)) { - if (methods++ < 3) { - if (methods > 1) tb_cat(tb, ", "); - tb_istr(tb, tree_ident(d)); - } - else - others++; - } - } - - if (others > 0) - tb_printf(tb, " and %d others", others); + type_t ptype = o->prefix ? get_type_or_null(o->prefix) : NULL; + if (ptype != NULL && type_is_protected(ptype)) { + diag_printf(d, "protected type %s has no method named %s", + type_pp(ptype), istr(o->name)); - diag_hint(d, NULL, "prefix of call is an object of protected " - "type %s which has %s %s", type_pp(ptype), - methods == 0 ? "no methods" - : (methods == 1 ? "method" : "methods"), tb_get(tb)); - } + scope_t *s = scope_for_type(o->nametab, ptype); + hint_for_typo(s, d, o->name, N_SUBPROGRAM); } - else + else { + diag_printf(d, "no visible subprogram declaration for %s", + istr(o->name)); hint_for_typo(o->nametab->top_scope, d, o->name, N_SUBPROGRAM); + } diag_emit(d); o->error = true; diff --git a/src/rt/reflect.c b/src/rt/reflect.c index 8821db35..c32cd66b 100644 --- a/src/rt/reflect.c +++ b/src/rt/reflect.c @@ -296,9 +296,9 @@ static value_mirror *get_value_mirror(void *context, jit_scalar_t value, avm->pt.f_subtype = vm->pt.f_subtype->pt.f_array; dimension_rec *dims = avm->pt.f_subtype->pt.f_dimension_data->ptr; - size_t total = 0; + size_t total = 1; for (int i = 0; i < avm->pt.f_subtype->pt.f_dimensions; i++) - total += dims[i].f_length; + total *= dims[i].f_length; avm->pt.f_elements = zero_alloc(sizeof(ffi_uarray_t) + total * sizeof(value_mirror *)); diff --git a/test/parse/typo.vhd b/test/parse/typo.vhd index 75c028f1..4366d679 100644 --- a/test/parse/typo.vhd +++ b/test/parse/typo.vhd @@ -9,6 +9,16 @@ architecture test of typo is foo, bar : integer; end record; + type pt is protected + procedure one; + procedure two; + end protected; + + type pt is protected body + procedure one is begin end procedure; + procedure two is begin end procedure; + end protected body; + begin assert rset; -- Error @@ -27,4 +37,10 @@ begin begin r.frodo := 1; end process; + + p3: process is + variable p : pt; + begin + p.onn; -- Error + end process; end architecture; diff --git a/test/test_parse.c b/test/test_parse.c index ba69313c..d9ce1a2e 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -4935,6 +4935,11 @@ static void typo_diag_fn(diag_t *d) "record type REC has no field named FRODO"); ck_assert_str_eq(diag_get_hint(d, 0), "did you mean FOO?"); break; + case 5: + ck_assert_str_eq(diag_get_text(d), + "protected type PT has no method named ONN"); + ck_assert_str_eq(diag_get_hint(d, 0), "did you mean ONE?"); + break; default: ck_abort_msg("too many diagnostics"); break; @@ -4943,6 +4948,8 @@ static void typo_diag_fn(diag_t *d) START_TEST(test_typo) { + set_standard(STD_02); + input_from_file(TESTDIR "/parse/typo.vhd"); diag_set_consumer(typo_diag_fn); @@ -4958,7 +4965,7 @@ START_TEST(test_typo) fail_unless(parse() == NULL); - fail_unless(error_count() == 5); + fail_unless(error_count() == 6); } END_TEST -- 2.39.2