ElixirLS Suppress warnings: where to put @dialyzer command?

After reading Dialyzer: suppress warning on a specific function, I think I know what I need but I don’t know where to put it.

I get a warning that is just wrong. It’s on code that runs and is often accessed, i.e. a major piece of the codebase. I have this warning in a few other places too where it should not be, and nothing I do gets rid if of it.

The pattern can never match the type.

{:error, _error}

{:ok, <<_::296>> | map()} | {:error, map(), number()}

I think I can use this to silence it, but where does it go?
@dialyzer {:Wno_match, handle_event/3} Should be maybe @dialyzer {:Wno_match, handle_event: 3}

I put it at the top of the module and I get the error: undefined variable "handle_event" invalid value for @dialyzer attribute: {:Wno_match, [handle_event: 3]} I guess I’m using to wrong also, hence the invalid value, but the docs are quite dense.

This is just the default LiveView handle_event.

PS: this the demo line for how to use this, but it makes no sense to me.

defmodule Myapp.Repo do
  use Ecto.Repo, otp_app: :myapp
  @dialyzer {:nowarn_function, rollback: 1}

Let’s start with where in the file this goes. Then we’ll handle the invalid value issue which has sprung up as I posted this.

I got it to work. The @dializer macro (it is a marco right?) goes at the top the module in question. Then you must put in the correct erlang disable warning option.

I had difficulty understanding the erlang docs, but the info was there the entire time. The warning options are these. I needed no_match

warn_option() =
    error_handling | no_behaviours | no_contracts | no_fail_call |
    no_fun_app | no_improper_lists | no_match | no_missing_calls |
    no_opaque | no_return | no_undefined_callbacks |
    no_underspecs | no_unknown | no_unused | underspecs |
    unknown | unmatched_returns | overspecs | specdiffs |
    extra_return | no_extra_return | missing_return |

So I put this at the top of my file and the warnings are now ignored.

defmodule MyApp.UserLive.Index do
  @dialyzer {:nowarn_function, handle_event: 3}
1 Like

It is actually a module attribute, not a macro :slight_smile:
Like macros, they are also compile-time.

1 Like

So I was correct in thinking I that was probably going to be wrong there :slight_smile:.
I still don’t really get all the terminology around here, but thanks for the link. It’ll help in fixing that.