Closed jesperes closed 4 years ago
The type meck:ret_spec() is declared opaque, but its documentation also says:
meck:ret_spec()
%% Note that any Erlang term `X' is a valid `ret_spec()' equivalent to %% `meck:val(X)'.
This is not compatible with how opaque types work, and will cause dialyzer errors when attempting to call e.g. meck:expect/4 like this:
opaque
meck:expect/4
meck:expect(foo, bar, 2, fun ?MODULE:run/2)
Dialyzer will complain that the code is attempting to pass something other than an opaque type as the 4th argument:
....: The call meck:expect(...) does not have an opaque term of type meck:ret_spec() as 4th argument
The only (compatible) way of fixing this is to change the ret_spec() type to
ret_spec()
-type ret_spec() :: any().
-module(foo). -export([main/0]). main() -> ok = meck:expect(foo, foo, 0, any_value).
dialyzer --plt ..../otp.plt ./foo.erl .../meck.beam
No dialyzer errors, since according to the documentation any_value is a valid ret_spec().
any_value
foo.erl:4: The call meck:expect ('foo', 'foo', 0, 'any_value') does not have an opaque term of type meck:ret_spec() as 4th argument
Thanks! I thin any() is the correct type here. Not sure why opaque() is there, perhaps Dialyzer got smarter or I simply just misunderstood the types. Care to make a PR? 😉
any()
opaque()
I'll fix a PR for it.
https://github.com/eproxus/meck/pull/213
Fixed by #213.
The type
meck:ret_spec()
is declared opaque, but its documentation also says:This is not compatible with how
opaque
types work, and will cause dialyzer errors when attempting to call e.g.meck:expect/4
like this:Dialyzer will complain that the code is attempting to pass something other than an opaque type as the 4th argument:
The only (compatible) way of fixing this is to change the
ret_spec()
type toReproduction Steps
Expected behavior
No dialyzer errors, since according to the documentation
any_value
is a validret_spec()
.Observed behavior
Versions