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

Fix dialyzer warnings #72

Merged
merged 9 commits into from
May 17, 2024
Merged

Fix dialyzer warnings #72

merged 9 commits into from
May 17, 2024

Conversation

bjosv
Copy link
Collaborator

@bjosv bjosv commented Mar 5, 2024

Run dialyzer on the test profile during make dialyzer, and in CI runs.
This PR fixes all dialyzer warnings found in the rebar3 test profile.

Fixes #71

bjosv added 7 commits March 5, 2024 13:49
Fixes Dialyzer warning:
The variable X__V can never match since previous clauses completely covered the type 'ok'
X__X::'dummy' can never succeed in test_command_support(Command)
eredis_cluster:qp/1 calls query/4 which can return {error, no_connection}

This fixes a dialyzer warning in eredis_cluster_tests "pipeline":
{'error', 'no_connection'} can never match the type [{'error','invalid_cluster_command'
 | 'no_connection' | 'tcp_closed' | bitstring()} | {'ok','undefined' | bitstring()}]
qa/1 and qa/2 return a list of what qw/2 returns, i.e redis_result()
The pattern {'ok', [ExpectedKey | _]} can never match the type
 [{'error','invalid_cluster_command' | 'no_connection' | 'tcp_closed' | bitstring()} | {'ok','undefined' | bitstring()}] |
  {'error','invalid_cluster_command' | 'no_connection' | 'tcp_closed' | bitstring()} | {'ok','undefined' | bitstring()}
This makes sure we run dialyzer on testcode during development and in CI.
Copy link
Collaborator

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose silencing the warnings is better than nothing, but these types are a bit of a mess.

@@ -6,10 +6,11 @@

-type redis_error_result() :: Reason::bitstring() | no_connection
| invalid_cluster_command | tcp_closed.
-type redis_success_result() :: Result::bitstring() | undefined.
-type redis_success_result() :: bitstring() | [bitstring()] | undefined.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where bitstring() (any multiple of bits) is used in these types, it should really be binary() (a multiple of 8 bits).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, but I got stuck when looking into why the change was done in 071b73b.
Maybe it was in early development stages and was then just kept? Can an EVAL return anything else in Redis?

Looking at eredis v1.0.8, used at the time of the change, it states binary() in the return_value() and no bitstring() mentioned in the eredis code either. Sure looks like we should change this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EVAL can return RESP data, like any other redis command. It's not even possible to receive parts of a byte over TCP.

Possibly some other spec used bitstring() which gave some warning when it was used with binary(). Do you know if there were any occurrences of bitstring prior to that change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No bitstrings can be found in the repo prior to that change.

bjosv added 2 commits May 17, 2024 11:27
From OTP-26 the `unknown function or type` warning is on by default.
Since dialyzer is now run from the test profile the test-applications
are also needed in the PLT, but only in the test profile.
A bitstring() is any multiple of bits while binary() is a multiple of 8 bits.
Since RESP is a binary protocol which uses control sequences encoded in
standard ASCII, i.e. 8 bits, the type binary() is the proper type to use.
@bjosv bjosv merged commit b7b7be2 into Nordix:master May 17, 2024
5 checks passed
@bjosv bjosv deleted the dialyzer branch May 17, 2024 12:32
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.

Type specs issue with Dialyzer
2 participants