Skip to content

Fix Dialyzer warnings#341

Merged
dumbbell merged 7 commits into
v0.17.xfrom
fix-dialyzer-warnings
Jul 28, 2025
Merged

Fix Dialyzer warnings#341
dumbbell merged 7 commits into
v0.17.xfrom
fix-dialyzer-warnings

Conversation

@dumbbell
Copy link
Copy Markdown
Collaborator

This is a collection of fixes of warnings reported by Dialyzer in Erlang/OTP 28.

These are not reported on CI yet because we can’t test against Erlang/OTP 28 until a new release of Rebar is published with the fix to make it work on Windows (erlang/rebar3#2954).

@dumbbell dumbbell added this to the v0.17.2 milestone Jul 23, 2025
@dumbbell dumbbell self-assigned this Jul 23, 2025
@dumbbell dumbbell added the bug Something isn't working label Jul 23, 2025
@dumbbell dumbbell force-pushed the fix-dialyzer-warnings branch from d48f769 to 7779211 Compare July 28, 2025 10:06
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (5d14401) to head (8ecac17).
⚠️ Report is 8 commits behind head on v0.17.x.

Additional details and impacted files
@@             Coverage Diff             @@
##           v0.17.x     #341      +/-   ##
===========================================
+ Coverage    89.59%   89.62%   +0.02%     
===========================================
  Files           22       22              
  Lines         3441     3450       +9     
===========================================
+ Hits          3083     3092       +9     
  Misses         358      358              
Flag Coverage Δ
erlang-26 89.53% <100.00%> (-0.04%) ⬇️
erlang-27 89.59% <100.00%> (+0.20%) ⬆️
os-ubuntu-latest 89.44% <100.00%> (+0.02%) ⬆️
os-windows-latest 89.62% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dumbbell added 6 commits July 28, 2025 15:10
[Why]
In `khepri_machine_v0`, it can only return a `tree_v0()` tree.

This was reported by Dialyzer in Erlang/OTP 28.
…()` terms

[Why]
`khepri_tree:tree()` can be either a `tree_v0()` or a `tree_v1()` which
are both opaque types. Therefore, they can't simply be compared with =:=
because it violates the contract that a e.g. a `tree_v0()` can't be
compared to a `tree_v1()` without knowing their internals.

This was reported by Dialyzer in Erlang/OTP 28.

[How]
We move the assert to `khepri_tree` which defines these opaque types and
thus has the right to compare them.
…` terms

[Why]
`khepri_machine:state()` can be either a `state_v0()` or a `state_v1()`
which are both opaque types. Therefore, they can't simply be compared
with =:= because it violates the contract that a e.g. a `state_v0()`
can't be compared to a `state_v1()` without knowing their internals.

This was reported by Dialyzer in Erlang/OTP 28.

[How]
We add an assert function to both `khepri_machine` and
`khepri_machine_v0`. They can inspect their respective version of the
state because they define it.
[Why]
This helps Dialyzer give more accurate warnings.
[Why]
There are several functions which use the same variable as an argument
and as their return value in their spec. Semantically, this means that
the argument is returned as is. Dialyzer doesn't enforce anything with
that (yet). But this is still incorrect.

So while working on several warnings, fix a few function specs. There
are still other functions that are incorrect in the same way.
@dumbbell dumbbell force-pushed the fix-dialyzer-warnings branch 2 times, most recently from 2899d34 to c76adba Compare July 28, 2025 14:06
[Why]
Our `#tree{}` type has two versions which differ on the type of the
`keep_while_conds_revidx` field. We also defined two type, `tree_v0()`
and `tree_v1()` which finished to define the two versions.

This was fine up to and including Erlang/OTP 27. However with Erlang/OTP
28, Dialyzer complained that `update_keep_while_conds/3` would never
return.

This was caused by the new "nominal type" property of opaque types: if I
understand correclty, based on the type specs, we couldn't modify the
`#tree{}` record in `update_keep_while_conds/3` because the returned
`#tree{}` might not be a `tree_v0()` or a `tree_v1()`.

[How]
In the end, we couldn't use the #tree{} record directly to define the
`tree_v0()` and `tree_v1()` types. We have to use an intermediate type
that takes the type of the `keep_while_conds_revidx` field, then use
this intermediate type in the definition of `tree_v0()` and `tree_v1()`.

We remove the type of the `keep_while_conds_revidx` field in the record
because it breaks the compilation with Erlang/OTP 27.
@dumbbell dumbbell force-pushed the fix-dialyzer-warnings branch from c76adba to 8ecac17 Compare July 28, 2025 14:49
@dumbbell dumbbell marked this pull request as ready for review July 28, 2025 15:03
@dumbbell dumbbell merged commit eeefdd6 into v0.17.x Jul 28, 2025
22 checks passed
@dumbbell dumbbell deleted the fix-dialyzer-warnings branch July 28, 2025 15:04
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 this pull request may close these issues.

1 participant