Hello all!<div><br></div><div>We are using parametric modules in our project and were quite happy with them unless we have started using Dialyzer.</div><div>Dialyzer fails on parametric modules because functions in parametric modules are expanded with module params argument on compilation stage - so function's specs are unmatched.</div>
<div><br></div><div>I know that parametric modules not the official part of Erlang, but I'd like to get both parametric modules and dialyzer working. I have tried to do some work on this:</div><div>1. Try to fix specs on parametric module's functions with parse_transform - simply extend specs on this stage, but this won't work, code just won't compile (because of specs for unknown functions)</div>
<div>2. More complicated approach - try to implement parametric modules with parse_transform (create "new" function and extend all module functions and specs). This looks working unless some code like</div><div>
SomeFun = local_fun/1, SomeFun(Arg) and some variations like this local function is assigned to record field.</div><div>3. Decided that there no way out besides patching OTP sources or not using parametric modules at all. After looking at OTP sources I have found, that parametric modules are expanded on on "<span style="line-height:16px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,'Liberation Mono',Courier,monospace">expand_module</span>" compiler pass. And on that stage specs are not expanded. I Have patched this stage with specs expand. All were correct, but dialyzer fails with message like specs were not fixed, so no luck... This happend because dialyzer using "abstract_code" from beam to extract specs and pass "<span style="line-height:16px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,'Liberation Mono',Courier,monospace">save_abstract_code</span>" is just before "<span style="line-height:16px;color:rgb(51,51,51);font-size:12px;white-space:pre-wrap;font-family:Consolas,'Liberation Mono',Courier,monospace">expand_module</span>" pass.</div>
<div>Simple changing these passes order broke dialyzer at all.</div><div>4. The last attempt were to patch dialyzer - on the stage, when it extracts specs info from beam's abstract_code section. At this place I insert function's specs expanding with last parametric parameter - and it works!</div>
<div><br></div><div>So the question is what the rigth way to make both parametric modules and dialyzer working?</div><div>At my opinion there are no way except OTP sources patching - but what the rigth place for making such patch? </div>
<div><br></div><div>I can attach my patch here but it is little ugly (I were tired by previous explorations) and I think I have chosen not rigth place for changing.</div><div> </div><div><br></div><div>Thanks,</div><div>
Lihanov Alexandr</div>