Skip to content

Commit 0c630f7

Browse files
committed
Fix Elixir 1.20.0-rc.0 warnings
Mainly this involves using the pin operator (`^`) in binary pattern matches where the size is matched out of a binary. `Mint.WebSocket.Frame.decode_opcode/1` is also refactored to pattern match the map directly, resolving this warning: warning: incompatible types given to Map.fetch/2: Map.fetch( %{ <<0::integer-size(4), ""::binary>> => :continuation, <<1::integer-size(4), ""::binary>> => :text, <<2::integer-size(4), ""::binary>> => :binary, <<8::integer-size(4), ""::binary>> => :close, <<9::integer-size(4), ""::binary>> => :ping, <<10::integer-size(4), ""::binary>> => :pong }, opcode ) the map: dynamic(%{bitstring() => :binary or :close or :continuation or :ping or :pong or :text}) does not have all required keys: dynamic() therefore this function will always return :error where "opcode" was given the type: # type: dynamic() # from: lib/mint/web_socket/frame.ex:289:22 opcode typing violation found at: │ 290 │ with :error <- Map.fetch(@reverse_opcodes, opcode) do │ ~ │ └─ lib/mint/web_socket/frame.ex:290:24: Mint.WebSocket.Frame.decode_opcode/1
1 parent ab070d4 commit 0c630f7

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
include:
15-
- erlang: "28.1"
16-
elixir: "1.19"
15+
- erlang: "28.3"
16+
elixir: "1.20.0-rc.1"
1717
lint: true
1818
coverage: true
1919
report: true
2020
dialyzer: true
2121
# One version down.
2222
- erlang: "27.2"
23-
elixir: "1.18"
23+
elixir: "1.19"
2424
# Oldest version. We technically support OTP 23 but hard to test in CI
2525
- erlang: "24.3"
26-
elixir: "1.14"
26+
elixir: "1.15"
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2929
MIX_ENV: test

lib/mint/web_socket/frame.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ defmodule Mint.WebSocket.Frame do
265265
defp decode_payload_and_mask(payload, masked?) do
266266
with {:ok, payload_length, rest} <- decode_payload_length(payload),
267267
{:ok, mask, rest} <- decode_mask(rest, masked?),
268-
<<payload::binary-size(payload_length), more::bitstring>> <- rest do
268+
<<payload::binary-size(^payload_length), more::bitstring>> <- rest do
269269
{:ok, payload, mask, more}
270270
else
271271
partial when is_binary(partial) -> :buffer
@@ -287,8 +287,9 @@ defmodule Mint.WebSocket.Frame do
287287
end
288288

289289
defp decode_opcode(opcode) do
290-
with :error <- Map.fetch(@reverse_opcodes, opcode) do
291-
{:error, {:unsupported_opcode, opcode}}
290+
case @reverse_opcodes do
291+
%{^opcode => kind} -> {:ok, kind}
292+
_ -> {:error, {:unsupported_opcode, opcode}}
292293
end
293294
end
294295

lib/mint/web_socket/per_message_deflate.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ defmodule Mint.WebSocket.PerMessageDeflate do
147147
data_size = byte_size(deflated) - 4
148148

149149
case deflated do
150-
<<deflated::binary-size(data_size), 0x00, 0x00, 0xFF, 0xFF>> -> deflated
150+
<<deflated::binary-size(^data_size), 0x00, 0x00, 0xFF, 0xFF>> -> deflated
151151
deflated -> deflated
152152
end
153153
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule MintWebSocket.MixProject do
77
[
88
app: :mint_web_socket,
99
version: "1.0.5",
10-
elixir: "~> 1.6",
10+
elixir: "~> 1.15",
1111
elixirc_paths: elixirc_paths(Mix.env()),
1212
erlc_paths: erlc_paths(Mix.env()),
1313
start_permanent: Mix.env() == :prod,

0 commit comments

Comments
 (0)