From 57b09b2ffbd1021d29e43fdc1f27da43f1b4ed23 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 10 Jun 2020 15:37:50 +0100 Subject: Fix #439 --- src/check_expr.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index a52295298..059ed917d 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7760,6 +7760,20 @@ bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValu return true; } +bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { + Ast *expr = unparen_expr(o->expr); + if (expr != nullptr) { + Entity *e = strip_entity_wrapping(entity_from_expr(expr)); + if (e != nullptr && e->kind == Entity_Procedure) { + return true; + } + if (expr->kind == Ast_ProcLit) { + add_type_and_value(c->info, expr, Addressing_Constant, type_of_expr(expr), exact_value_procedure(expr)); + return true; + } + } + return o->mode == Addressing_Constant; +} ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { @@ -7780,7 +7794,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type c->state_flags = out; } - ExprKind kind = Expr_Stmt; o->mode = Addressing_Invalid; @@ -8242,7 +8255,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type is_constant = false; } if (is_constant) { - is_constant = o.mode == Addressing_Constant; + is_constant = check_is_operand_compound_lit_constant(c, &o); } check_assignment(c, &o, field->type, str_lit("structure literal")); @@ -8277,7 +8290,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type is_constant = false; } if (is_constant) { - is_constant = o.mode == Addressing_Constant; + is_constant = check_is_operand_compound_lit_constant(c, &o); } check_assignment(c, &o, field->type, str_lit("structure literal")); -- cgit v1.2.3