Bitwise encoder stores permissions as %{entity_atom => %{permission_string => 2**bit}}.
But Atom encoder stores permissions as %{entity_atom => [permission_atom, ...]}, which does no satisfy type spec.
As well as Text encoder which stores permissions as %{entity_atom => [permission_string, ...]}.
In this PR I've improved this spec to avoid such an error.
when is_integer(value) clause of Guardian.Permissions.do_decode_permissions matches the same clause of BitwiseEncoding.decode. But AtomEncoding.decode and TextEncoding.decode does not have is_integer clause, which leads to this error.
Here I rearranged guard clauses and make them less strict.
Hello.
Here is an example of source code used in one of my projects:
The permission encoding and decoding works perfectly, but dialyxir raises errors like that:
First error is connected to this type spec: https://github.com/ueberauth/guardian/blob/75b7d8fdb7eb61f3048ce6b9394d377a5b004b52/lib/guardian/permissions.ex#L110
Bitwise encoder stores permissions as
%{entity_atom => %{permission_string => 2**bit}}
. But Atom encoder stores permissions as%{entity_atom => [permission_atom, ...]}
, which does no satisfy type spec. As well as Text encoder which stores permissions as%{entity_atom => [permission_string, ...]}
.In this PR I've improved this spec to avoid such an error.
Second error is connected to these lines: https://github.com/ueberauth/guardian/blob/75b7d8fdb7eb61f3048ce6b9394d377a5b004b52/lib/guardian/permissions.ex#L284-L289 https://github.com/ueberauth/guardian/blob/75b7d8fdb7/lib/guardian/permissions/atom_encoding.ex#L28-L30
when is_integer(value)
clause ofGuardian.Permissions.do_decode_permissions
matches the same clause ofBitwiseEncoding.decode
. ButAtomEncoding.decode
andTextEncoding.decode
does not haveis_integer
clause, which leads to this error.Here I rearranged guard clauses and make them less strict.
All tests were passes successfully: