Elixir / Erlang Dialyzer: Why should the behavior callback type be a subtype instead of a supertype?

I have X behavior and callback function with parameter type:

%{a: any}

Module Y implements the behavior of X, and the callback function in the implementing module Y has the parameter type:

%{a: any, b: any}

Dialyzer dislikes and complains:

(#{'a':=_, 'b':=_, _=>_}) 
is not a supertype of 
#{'a':=_}

This means that the dialyzer is trying to determine whether the type of the callback parameter in the implementation of module Y is a supertype of type param in the behavior of X. In other words, it asks:

Is the behavior of the callback type X a %{a: any}subtype implementing the module Y parameter type %{a: any, b: any}?

Why does the dialyzer expect the paramback type of the behavior callback to be a subtype instead of a supertype?

:

S T, S <: T, S , T. , S masquerade T.

, T, - S. - . , , .

, .

. , SO Erlang (Elixir) Dialyzer - .

+1
1

. X %{a: any}, , , , . %{a: 1}. %{a: any, b: any}, %{a: any}, , %{a: 1}, .

, %{a: any, b: any}, %{a: any}, , %{a: any} %{a: any, b: any}, %{a: 1, b: 2} - .

+2

Source: https://habr.com/ru/post/1685777/


All Articles