I run Dialyzer on the following MVR piece of code which passes the test_function
except for the IncorrectMap
. Why is that the case when I deliberately return different PlayersMapNew
for the case branches although they are specified to be the same. And how can I force Dialyzer to be more strict about my code, such that States are easier to manage keep track of.
My concern especially is if I have filled out the way of making a map type checking correctly , in order to make sure that it is Done in accordance with the documentation. The latter I think is a bit scarce. Can one actually check down to the individual key of a map , whether it is correct or not?
-module(example_module).
-export([my_function/1, state_changer/3, test_function/0]).
-type map_arg() :: #{key1 => integer(), key2 => atom()}.
-type move() :: rock | paper | scissor.
-type playersmap() :: #{players => {pid(), pid()}} | #{players => {pid(), pid()}, fst_mover => {{pid(),_}, move()}}.
-spec my_function(Map_arg :: map_arg()) -> ok.
my_function(Map) ->
ok.
test_function() ->
CorrectMap = #{key1 => 1, key2 => 'value'},
IncorrectMap = #{key1 => 1, key2 => 2},
my_function(CorrectMap),
my_function(IncorrectMap),
state_changer({move, rock}, {self(), tag}, #{players => {self(), self()}, fst_mover => {{self(), tag}, scissor}}).
-spec state_changer({move, Choice :: move()}, From :: {pid(), _}, PlayersMap :: playersmap()) -> {reply, playersmap()}.
state_changer({move, Choice}, From, PlayersMap) ->
{CurId, _} = From,
{P1Id, P2Id} = maps:get(players, PlayersMap),
case CurId of
P1Id ->
PlayersMapNew = maps:put(fst_mover, {From, Choice}, PlayersMap),
{reply, PlayersMapNew};
P2Id ->
PlayersMapNew = maps:put(fst_mover, {Choice, From}, PlayersMap),
{reply, PlayersMapNew}
end.