Fix compilation warnings#210
Open
gilbertwong96 wants to merge 2 commits into
Open
Conversation
The Elixir compiler warns when a variable used in a bitstring size
specifier is defined outside the match. The compiler instructs the
author to pin the variable with the ^ operator so it is clear that the
existing binding is being matched against, not a new one being bound.
Apply the pin operator to the 6 affected bitstring segments:
* lib/myxql/protocol.ex
- encode_packet/4: pin max_packet_size in size(^max_packet_size)
- decode_initial_handshake/1: pin take in binary-size(^take)
* lib/myxql/protocol/types.ex
- take_string_lenenc/1: pin size in string(^size)
* lib/myxql/protocol/values.ex
- decode_binary_row/2: pin size in uint(^size)
- decode_bit/2: pin both pad and size in size(^pad), size(^size)
Also drop the unused 'require Bitwise' from MyXQL.Protocol.Auth. All
call sites in the codebase use the fully-qualified Bitwise.bxor/band/bor
form, so the require is dead. The original TODO comment said to remove
it once Elixir 1.10+ is required; mix.exs declares 'elixir: ~> 1.13',
so that bar is cleared.
Behaviour is unchanged: the pin operator in a bitstring size position
is purely a syntactic clarification. mix compile --warnings-as-errors
passes cleanly.
Auto-resolved by mix deps.get to the latest versions allowed by the ranges declared in mix.exs. Notable updates: * geo 3.4.0 -> 4.1.0 (already supported: '~> 3.4 or ~> 4.0') * db_connection 2.4.1 -> 2.10.1 * decimal 3.0.0 -> 3.1.1 * dialyxir 1.0.0 -> 1.4.7 * benchee 1.0.1 -> 1.5.1 (pulls in new dev dep statistex 1.1.1) * telemetry 1.0.0 -> 1.4.2 * ex_doc 0.40.1 -> 0.40.3 * erlex 0.2.6 -> 0.2.9 * deep_merge 1.0.0 -> 1.0.2 * table 0.1.0 -> 0.1.2 * makeup_erlang 1.0.3 -> 1.1.0 No code changes required for any of these. mix compile passes with no warnings after the previous commit's warning fixes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleans up the 7 compilation warnings emitted by
mix compileon the current Elixir toolchain. Also picks up the dev/test dependency bumps auto-resolved bymix deps.get.Warning fixes (commit 1)
The Elixir compiler warns whenever a variable used in a bitstring size specifier is defined outside the match itself:
Per the Elixir docs the canonical fix is the pin operator. Six bitstring segments and one
requiredirective are touched:lib/myxql/protocol.ex(encode_packet/4)size(max_packet_size)→size(^max_packet_size)lib/myxql/protocol.ex(decode_initial_handshake/1)binary-size(take)→binary-size(^take)lib/myxql/protocol/types.ex(take_string_lenenc/1)string(size)→string(^size)lib/myxql/protocol/values.ex(decode_binary_row/2)uint(size)→uint(^size)lib/myxql/protocol/values.ex(decode_bit/2)size(pad), size(size)→size(^pad), size(^size)lib/myxql/protocol/auth.exrequire Bitwise(the file's TODO said to drop it once we require Elixir 1.10+; mix.exs already declares~> 1.13)Semantics are unchanged — the pin operator in a bitstring size position is purely a syntactic clarification.
mix compile --warnings-as-errorspasses cleanly.Dependency updates (commit 2)
mix.lockwas updated to the latest versions allowed by the ranges inmix.exs. The geo upgrade from 3.4.0 → 4.1.0 is already supported by the existing~> 3.4 or ~> 4.0requirement. Per the geo 4.0.0 changelog, the breaking changes are confined toGeo.JSON(SRID defaults to 4326; string coordinates coerced to numbers); myxql usesGeo.WKBexclusively, so the upgrade is transparent here. No code changes needed for any of the dep updates.Test plan
mix compile --warnings-as-errorspasses with no warnings in myxqlMIX_ENV=test mix compilepasses with no warnings in myxqltest/myxql/protocol/values_test.exs)