Warning of "The inferred type for the 1st argument of..."

Hello, this warning is shown in my VSCode.

The inferred type for the 1st argument of save/2 (
          #{'__struct__' := 'Elixir.EServer.Bracket.Builder.Match',
            'depth' := _,
            'left' :=
                #{'__struct__' :=
                      'Elixir.EServer.Bracket.Builder.Entry' |
                      'Elixir.EServer.Bracket.Builder.Match',
                  'depth' := _,
                  _ => _},
            'right' :=
                #{'__struct__' :=
                      'Elixir.EServer.Bracket.Builder.Entry' |
                      'Elixir.EServer.Bracket.Builder.Match',
                  'depth' := _,
                  _ => _},
            _ => _}) is not a supertype of 
          #{'__struct__' := 'Elixir.EServer.Bracket.Builder.Match',
            'depth' := integer(),
            'left' :=
                'Elixir.EServer.Bracket.Builder.Entry' |
                'Elixir.EServer.Bracket.Builder.Match' | 'nil',
            'right' :=
                'Elixir.EServer.Bracket.Builder.Entry' |
                'Elixir.EServer.Bracket.Builder.Match' | 'nil'}, which is expected type for this argument in the callback of the 'Elixir.EServer.Bracket.Builder' behaviourElixirLS Dialyzer

It is on this line:

use EServer.Bracket.Builder, entry_id_type: :string

It happens when I use macro. Do you know something about this? I’d show you other codes as needed.

Looks like you have a save/2 callback in your behaviour and you have specified the type of the first argument as

%EServer.Bracket.Builder.Match{
  depth: integer(),
  left: EServer.Bracket.Builder.Entry | EServer.Bracket.Builder.Match | nil,
  right: EServer.Bracket.Builder.Entry | EServer.Bracket.Builder.Match | nil
}

But you are calling that function with the first argument being of the type (example):

%EServer.Bracket.Builder.Match{
  depth: …,
  left: %EServer.Bracket.Builder.Entry{…},
  right: %EServer.Bracket.Builder.Entry{…}
}

You can see that the inferred type (the latter example) differs from the specified type in that left and right are structs. In the type they are specified as just module names (atoms).

If this hasn’t helped you enough, can you show the typespec of function save/2 and how you use it? It’s probably in the EServer.Bracket.Builder module somewhere in the macro.

1 Like

Hi, it worked! Thank you so much!