From a5aaf1706d061fc6d9319b46077d1a9d5df4ccd3 Mon Sep 17 00:00:00 2001 From: Bastien CHAMAGNE Date: Fri, 21 Apr 2023 10:36:40 +0200 Subject: [PATCH] The is_function_call? was returning the wrong result if the alias was a complex one (length of 2+). --- lib/archethic/contracts/interpreter/ast_helper.ex | 2 +- .../interpreter/action_interpreter_test.exs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/archethic/contracts/interpreter/ast_helper.ex b/lib/archethic/contracts/interpreter/ast_helper.ex index b3485851e..b15bcdb1c 100644 --- a/lib/archethic/contracts/interpreter/ast_helper.ex +++ b/lib/archethic/contracts/interpreter/ast_helper.ex @@ -135,7 +135,7 @@ defmodule Archethic.Contracts.Interpreter.ASTHelper do """ @spec is_function_call?(Macro.t()) :: boolean() def is_function_call?({{:atom, _}, _, list}) when is_list(list), do: true - def is_function_call?({{:., _, [{:__aliases__, _, [_]}, _]}, _, _}), do: true + def is_function_call?({{:., _, [{:__aliases__, _, _}, _]}, _, _}), do: true def is_function_call?(_), do: false @doc """ diff --git a/test/archethic/contracts/interpreter/action_interpreter_test.exs b/test/archethic/contracts/interpreter/action_interpreter_test.exs index baf881649..dde7adcee 100644 --- a/test/archethic/contracts/interpreter/action_interpreter_test.exs +++ b/test/archethic/contracts/interpreter/action_interpreter_test.exs @@ -238,6 +238,21 @@ defmodule Archethic.Contracts.Interpreter.ActionInterpreterTest do |> ActionInterpreter.parse() end + test "should be able to use a function call as a parameter to a lib function" do + code = ~S""" + actions triggered_by: transaction do + count = List.size(Contract.get_calls()) + Contract.set_content(count) + end + """ + + assert {:ok, :transaction, _} = + code + |> Interpreter.sanitize_code() + |> elem(1) + |> ActionInterpreter.parse() + end + test "should not be able to use wrong types in contract functions" do code = ~S""" actions triggered_by: transaction do