Skip to content

Commit

Permalink
The is_function_call? was returning the wrong result if the alias was…
Browse files Browse the repository at this point in the history
… a complex one (length of 2+).
  • Loading branch information
bchamagne authored and Neylix committed Apr 26, 2023
1 parent b396f1c commit a5aaf17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/archethic/contracts/interpreter/ast_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
15 changes: 15 additions & 0 deletions test/archethic/contracts/interpreter/action_interpreter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a5aaf17

Please sign in to comment.