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

Address unmatched return warnings from Dialyzer #16

Merged

Conversation

seancribbs
Copy link
Contributor

If you use JokenJwks.DefaultStrategyTemplate in your own code and run dialyzer
to check with -Wunmatched_returns, three warnings appear on the line where
use was put. Adding location: :keep to the quote in
JokenJwks.DefaultStrategyTemplate reveals the following lines:

  lib/joken_jwks/default_strategy_template.ex:105: Expression produces a value of type
          atom() | ets:tid(), but this value is unmatched
  lib/joken_jwks/default_strategy_template.ex:183: Expression produces a value of type
          {'ok', pid()}, but this value is unmatched
  lib/joken_jwks/default_strategy_template.ex:216: Expression produces a value of type
          'ok' | {'ok', pid()}, but this value is unmatched

This commit resolves the above warnings as following (respectively):

  • The call to :ets.new/2 uses the :named_table option, and so should always
    return the atom that was passed as the table name, namely __MODULE__.
  • The call to start_fetch_signers/2 has the same return type as
    Task.start/1, which is {:ok, pid()}, so we match on {:ok, _}.
  • The call to check_fetch could return :ok or {:ok, pid()} based on the
    branches of the case expression inside the function. Since there weren't any
    simple ways to resolve this, I chose to match with _.

If you `use JokenJwks.DefaultStrategyTemplate` in your own code and run dialyzer
to check with `-Wunmatched_returns`, three warnings appear on the line where
`use` was put. Adding `location: :keep` to the `quote` in
`JokenJwks.DefaultStrategyTemplate` reveals the following lines:

  lib/joken_jwks/default_strategy_template.ex:105: Expression produces a value of type
          atom() | ets:tid(), but this value is unmatched
  lib/joken_jwks/default_strategy_template.ex:183: Expression produces a value of type
          {'ok', pid()}, but this value is unmatched
  lib/joken_jwks/default_strategy_template.ex:216: Expression produces a value of type
          'ok' | {'ok', pid()}, but this value is unmatched

This commit resolves the above warnings as following (respectively):

* The call to `:ets.new/2` uses the `:named_table` option, and so should always
  return the atom that was passed as the table name, namely `__MODULE__`.
* The call to `start_fetch_signers/2` has the same return type as
  `Task.start/1`, which is `{:ok, pid()}`, so we match on `{:ok, _}`.
* The call to `check_fetch` could return `:ok` or `{:ok, pid()}` based on the
  branches of the `case` expression inside the function. Since there weren't any
  simple ways to resolve this, I chose to match with `_`.
@victorolinasc
Copy link
Collaborator

Thanks a lot @seancribbs !

@victorolinasc victorolinasc merged commit c0ad63b into joken-elixir:master Aug 7, 2020
@seancribbs
Copy link
Contributor Author

Thank you for the merge! ❤️🧡💛💚💙💜

@victorolinasc
Copy link
Collaborator

I will run master on some services we use it here and if all goes well I'll release a patch version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants