Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meck:ret_spec() opaqueness violates documented usage patterns #212

Closed
jesperes opened this issue Jun 24, 2020 · 4 comments
Closed

meck:ret_spec() opaqueness violates documented usage patterns #212

jesperes opened this issue Jun 24, 2020 · 4 comments

Comments

@jesperes
Copy link
Contributor

The type meck:ret_spec() is declared opaque, but its documentation also says:

%% 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:

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

-type ret_spec() :: any().

Reproduction Steps

  1. Given this module:
-module(foo).
-export([main/0]).
main() ->
  ok = meck:expect(foo, foo, 0, any_value).
  1. Run dialyzer
dialyzer --plt ..../otp.plt  ./foo.erl .../meck.beam

Expected behavior

No dialyzer errors, since according to the documentation any_value is a valid ret_spec().

Observed behavior

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

Versions

  • Meck version: 0.8.13 (+ some local unrelated changes)
  • Erlang version: OTP 22.2.7
@eproxus
Copy link
Owner

eproxus commented Jun 24, 2020

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? 😉

@jesperes
Copy link
Contributor Author

I'll fix a PR for it.

@jesperes
Copy link
Contributor Author

#213

@eproxus
Copy link
Owner

eproxus commented Jun 25, 2020

Fixed by #213.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants