From cb817d6c769060e0a1c9d6e49b45c41da7cbd1cc Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Fri, 16 Dec 2022 12:22:02 +0300 Subject: [PATCH] Allow records to be used as compile time constants --- src/aeso_ast_infer_types.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 4b9113b..0778735 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -2011,7 +2011,7 @@ infer_expr(Env = #env{ current_const = none }, {switch, Attrs, Expr, Cases}) -> NewCases = [infer_case(Env, As, Pattern, ExprType, GuardedBranches, SwitchType) || {'case', As, Pattern, GuardedBranches} <- Cases], {typed, Attrs, {switch, Attrs, NewExpr, NewCases}, SwitchType}; -infer_expr(Env = #env{ current_const = none }, {record, Attrs, Fields}) -> +infer_expr(Env, {record, Attrs, Fields}) -> RecordType = fresh_uvar(Attrs), NewFields = [{field, A, FieldName, infer_expr(Env, Expr)} || {field, A, FieldName, Expr} <- Fields], @@ -2269,10 +2269,12 @@ infer_block(Env, Attrs, [E|Rest], BlockType) -> [NewE|infer_block(Env, Attrs, Rest, BlockType)]. infer_const(Env, {letval, Ann, Id = {id, AnnId, _}, Expr}) -> + create_constraints(), NewExpr = {typed, _, _, Type} = infer_expr(Env#env{ current_const = Id }, Expr), + solve_then_destroy_and_report_unsolved_constraints(Env), IdType = setelement(2, Type, AnnId), NewId = {typed, aeso_syntax:get_ann(Id), Id, IdType}, - {letval, Ann, NewId, NewExpr}. + instantiate({letval, Ann, NewId, NewExpr}). infer_infix({BoolOp, As}) when BoolOp =:= '&&'; BoolOp =:= '||' ->