Elixir: Usage of `defprotocol` sometimes causes dialyzer warning

Created on 12 Dec 2017  路  11Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir & Erlang versions (elixir --version):

    Erlang/OTP 20 [erts-9.1.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] 
    [kernel-poll:false] [dtrace]
    
    Elixir 1.5.2
    
  • Operating system: OSX (sw_vers):

    ProductName:  Mac OS X
    ProductVersion:   10.13.1
    BuildVersion: 17B1003
    

    Current behavior

Any usage of the defprotocol macro in a project dependency causes dialyzer to complain:

Guard test 'or'('false','false') can never succeed

Expected behavior

It would be nice if this did not occur, as every project containing dependencies with protocols must then mark these warnings as allowed to get clean dialyzer runs. It's one thing for the language to not get a clean dialyzer run itself but it is a bit of a hassle if it causes projects' dialyzer runs to fail indirectly because of how the defprotocol macro is implemented.

Dialyzer can't provide very useful backtracing into the cause of this since it is a macro. Since this is a low-priority, nice-to-have, hard-to-implement issue I'm fine if this is just closed out but I thought it'd be nice to have it reported somewhere and I couldn't see any such a report anywhere already.

If closed off I will approach maintainers of Elixir dialyzer tasks and see if this can instead be included in a set of default ignores.

Elixir Bug Intermediate

Most helpful comment

@christhekeele please provide an example (and include exact Erlang version) because our own protocol dialyzer test does not warn. If I add protocol consolidation to the test I get different warnings on master but no warning on v1.5.2.

protocol_opaque.ex:8: Function any_impl_for/0 will never be called
protocol_opaque.ex:8: Function 'impl_for?'/1 will never be called

Note we consolidate by default since 1.4 when using mix.

All 11 comments

Confirmed that the exact same warning is emitted in prod mode, so this is not a consolidation thing.

@christhekeele please provide an example (and include exact Erlang version) because our own protocol dialyzer test does not warn. If I add protocol consolidation to the test I get different warnings on master but no warning on v1.5.2.

protocol_opaque.ex:8: Function any_impl_for/0 will never be called
protocol_opaque.ex:8: Function 'impl_for?'/1 will never be called

Note we consolidate by default since 1.4 when using mix.

I've created a clean mix project reproducing this issue in my orphaned branch here. Running mix dialyzer produces the dialyzer errors documented in the dialyzer.output file.

@fishcakez I've included richer erlang and OS version info in my description.

I'm using the newer dialyzex package in my example, but this does not affect the outcome versus dialyxir.

The main reason why I am using that library in particular is because it makes it clean to ignore these errant warnings, as demonstrated here.

I've created a build matrix to diagnose the versions of Elixir and OTP where this occurs. (Takes quite some time to run, no conclusions to draw yet.)

@christhekeele don't worry the issue is trivial, fallback to any with consolidation creates guard clause that can never match. In future please try to give more minimal examples or at least full warnings. You reported that it was all protocols and consolidation didn't matter, which made this confusing to understand.

Yeah, I didn't have time to dig into it until tonight; but I knew when I noticed and silenced the warning yesterday that I'd never get around to reporting it if I didn't then.

In the future I'll avoid speculating on the probable cause if I haven't had time to do more investigation, though! 馃槃 馃憤

Unless you are on the heels of a fix yourself, I'm confident that armed with your synopsis I can submit a patch for this. Feel free to assign to me if you are not working on this, and thanks for your help!

@christhekeele please do send a PR!

I will go ahead with this since we are working towards a release candidate for v1.6.

Was this page helpful?
0 / 5 - 0 ratings