From 87bc9275fe0b4138804290e348a3f9d05d199cf0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 27 Mar 2021 16:49:56 +0000 Subject: Correct poly type determination of a `where` clause for an enumerated array --- src/check_type.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/check_type.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index e65e538ae..5e99ca6fd 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2554,21 +2554,32 @@ i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { if (o->mode != Addressing_Constant) { if (o->mode != Addressing_Invalid) { + Entity *entity = entity_of_node(o->expr); + bool is_poly_type = false; + if (entity != nullptr) { + is_poly_type = \ + entity->kind == Entity_TypeName && + entity->type == t_typeid && + entity->flags&EntityFlag_PolyConst; + } + + // NOTE(bill, 2021-03-27): Improve error message for parametric polymorphic parameters which want to generate + // and enumerated array but cannot determine what it ought to be yet + if (ctx->allow_polymorphic_types && is_poly_type) { + return 0; + } + gbString s = expr_to_string(o->expr); error(e, "Array count must be a constant integer, got %s", s); gb_string_free(s); - Entity *e = entity_of_node(o->expr); - if (e != nullptr) { - // NOTE(bill, 2021-03-27): Improve error message for parametric polymorphic parameters which want to generate - // and enumerated array but cannot determine what it ought to be yet - if (ctx->allow_polymorphic_types && e->kind == Entity_TypeName && e->type == t_typeid && e->flags&EntityFlag_PolyConst) { - error_line("\tSuggestion: 'where' clause may be required to restrict the enumerated array index type to an enum\n"); - error_line("\t 'where intrinsics.type_is_enum(%.*s)'\n", LIT(e->token.string)); - } + if (is_poly_type) { + error_line("\tSuggestion: 'where' clause may be required to restrict the enumerated array index type to an enum\n"); + error_line("\t 'where intrinsics.type_is_enum(%.*s)'\n", LIT(entity->token.string)); } o->mode = Addressing_Invalid; + o->type = t_invalid; } return 0; } -- cgit v1.2.3