Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors on Parametrized Types #29

Closed
hickscorp opened this issue Apr 9, 2020 · 3 comments · Fixed by #36
Closed

Errors on Parametrized Types #29

hickscorp opened this issue Apr 9, 2020 · 3 comments · Fixed by #36
Labels
bug Something isn't working

Comments

@hickscorp
Copy link

hickscorp commented Apr 9, 2020

From Ecto.Changeset, there is a t() defined such as:

  @type t(data_type) :: %Changeset{valid?: boolean(),
                        ...
                        data: data_type,
                        ...
                        types: nil | %{atom => Ecto.Type.t}}

In our behaviour, we have something like:

  @type user_changeset :: Ecto.Changeset.t(User.t())

  @callback password_operation(user_changeset) :: user_changeset
  @callback password_operation(user_changeset, attrs :: map) :: user_changeset

In our implementation:

  @type user_changeset :: Ecto.Changeset.t(User.t())
  @impl CredentialsHelper
  @spec password_operation(user_changeset) :: user_changeset
  @spec password_operation(user_changeset, map) :: user_changeset
  def password_operation(cs, attrs \\ %{}),
    do: ...

When trying to stub or expect, Hammox raises:

     ** (FunctionClauseError) no function clause matching in Hammox.TypeEngine.match_type/2

     The following arguments were given to Hammox.TypeEngine.match_type/2:
     
         # 1
         nil
     
         # 2
         {:var, 282, :data_type}

Note: we tried every possible combination of typing here - directly Ecto.Changeset.t, Ecto.Changeset.t(any) etc. Only replacing the changeset type by any on the behaviour seems to fix the problem.

@msz msz added the bug Something isn't working label Apr 12, 2020
@msz
Copy link
Owner

msz commented Apr 13, 2020

Hi, thank you for reporting this!

Are you using the latest version? We had #16 which looks like the same problem, and the fix for it was shipped in v0.2.1.

@hickscorp
Copy link
Author

hickscorp commented Apr 15, 2020

No, unfortunately it still doesn't work. We're on v0.2.3.

In our behaviour, all of these fail:

@type changeset :: Ecto.Changeset.t()
@type changeset :: Ecto.Changeset.t(any)
@type changeset :: Ecto.Changeset.t(User.t())

But what is very interesting is that this works:

@type changeset :: %Ecto.Changeset{data: User.t()}

@msz
Copy link
Owner

msz commented Apr 28, 2020

Reproduced this on my side. Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants