gradient icon indicating copy to clipboard operation
gradient copied to clipboard

The spec follows a spec with different name/arity

Open yordis opened this issue 2 years ago • 9 comments

Original issue: https://github.com/josefs/Gradualizer/issues/421#issuecomment-1149618778

I am getting the following issues:

commands/accept_address_transfer.ex: The spec new/1 on line 5 follows a spec with different name/arity
commands/accept_address_transfer.ex: The spec put_aggregate_id/2 on line 5 follows a spec with different name/arity
commands/accept_address_transfer.ex: The spec put_aggregate_id/2 on line 5 doesn't match the function name/arity
domain/address_transfer.ex: The spec identifier/0 on line 10 doesn't match the function name/arity

Here is the code where it is happening:

defmodule AddressTransfers.AcceptAddressTransfer do
  use OnePiece.Commanded.CommandHandler
  use OnePiece.Commanded.Command, aggregate_identifier: :address_transfer_id

  embedded_schema do
    field :accepted_at, :utc_datetime_usec
  end

  # ...
end

defmodule AddressTransfers.AddressTransfer do
  use OnePiece.Commanded.Entity, identifier: :address_transfer_id

  embedded_schema do
  end

  # ....
end

I am using the following package to expand the macros: https://github.com/straw-hat-team/beam-monorepo/tree/master/apps/one_piece_commanded/lib/one_piece/commanded

It seems that all the methods added by the macro are not working or something, but I added the typespec correctly (as far as I can tell, my apologies if was something obvious)

yordis avatar Jun 08 '22 15:06 yordis

This error also happens in gradient codebase itself, the following spec in line 64 fails:

  @spec context_mapper_map(forms(), tokens(), options()) :: forms()
  def context_mapper_map(forms, tokens, opts, mapper \\ &mapper/3)
lib/gradient/ast_specifier.ex:64: The spec context_mapper_map/3 doesn't match the function name/arity

This error is because of the optional argument. Once a typespec for it is added, it stops complaining:

  @type mapper_fn() :: (term(), term(), term()-> term())
  @spec context_mapper_map(forms(), tokens(), options(), mapper_fn()) :: forms()

I think it would help a lot in this case to show the spec and surrounding code, like I've seen in some other errors.

rodrigues avatar Jun 24 '22 20:06 rodrigues

This error is because of the optional argument.

What optional argument are you referring to? IN the example I shared I didn't have any so I want to make sure I understood 😄

yordis avatar Jun 24 '22 21:06 yordis

@yordis yeah now I've looked a bit more your code, indeed I don't see optional args missing in spec for your case, I guess the scenario in gradient was a valid one, your seems to me like a false positive 🤔

rodrigues avatar Jun 24 '22 21:06 rodrigues

Indeed, I think @yordis's example raises a false positive. Alas, with macros generating code it might be hard to avoid all of these without fixing all macros, that's why we'll resolve to #102 to avoid false positives in such cases - it's not perfect, but a good start.

erszcz avatar Jun 27 '22 07:06 erszcz

Hey peeps, any update on this one? I wish I could contribute, but I am not qualified today. Almost everything failing today is due to this one.

yordis avatar Sep 07 '22 18:09 yordis

@yordis No progress on the fix yet. Alas, we have very limited bandwidth :/ However, you can mute this warning by using no_ex_check option or --no-ex-check command-line flag.

erszcz avatar Sep 08 '22 13:09 erszcz

@yordis Could you confirm if #102 fixed this for you?

erszcz avatar Sep 18 '22 19:09 erszcz

With the following SHA

"gradient": {:git, "https://github.com/esl/gradient.git", "a4169bde64eeda4a692654932cc9f0a3ab79b2d5", []},

It still is not working. Same issues as before

yordis avatar Sep 20 '22 01:09 yordis

@yordis thanks, I'm reopening then.

erszcz avatar Sep 20 '22 08:09 erszcz