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

Module references in typespecs are not included when renaming modules #206

Closed
jesperes opened this issue Jan 2, 2020 · 2 comments
Closed
Labels

Comments

@jesperes
Copy link
Contributor

jesperes commented Jan 2, 2020

Module references in typespecs are not included when renaming modules. This causes problems with OTP 22, as specs referencing functions in other modules are no longer permitted. See e.g. OTP-15563 in http://erlang.org/download/otp_src_22.0.readme:

OTP-15563    Application(s): compiler, stdlib
               Related Id(s): ERL-845, OTP-15562

               Do not allow function specifications for functions
               residing in other modules.

Reproduction Steps

  1. Given the following module:
-module(foo).
-export([bar/0]).
-spec ?MODULE:bar() -> ok.
bar() -> ok.
  1. Compile foo.erl with erlc +debug_info foo.erl
  2. Start an Erlang shell and call mock:new(foo, [passthrough])

Expected behavior

mock:new/2 should return ok.

Observed behavior

mock:new/2 throws an exception:

** exception error: {compile_forms,{error,[{"foo.erl",
                                            [{4,erl_lint,{bad_module,{foo,main,0}}}]}],
                                          []}}
     in function  meck_proc:start/2
        called as meck_proc:start(foo,[passthrough])

Versions

  • Meck 0.8.12
  • Erlang/OTP 22.1.8
@jesperes
Copy link
Contributor Author

jesperes commented Jan 2, 2020

The problem is in meck_code:rename_module/2 which only modifieds the module attribute, and ignores any typespecs found in the file:

-spec rename_module(erlang_form(), module()) -> erlang_form().
rename_module([{attribute, Line, module, OldAttribute}|T], NewName) ->
    case OldAttribute of
        {_OldName, Variables} ->
            [{attribute, Line, module, {NewName, Variables}}|T];
        _OldName ->
            [{attribute, Line, module, NewName}|T]
    end;
rename_module([H|T], NewName) ->
    [H|rename_module(T, NewName)].

@eproxus eproxus added the bug label Feb 2, 2020
@eproxus
Copy link
Owner

eproxus commented Feb 2, 2020

Thanks for the pointer! I'll take a look at as soon as I can.

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

No branches or pull requests

2 participants