Skip to content

Commit

Permalink
Fix Elixir 1.15 warnings (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
moogle19 authored Jul 29, 2022
1 parent 57cf96d commit 8e4f0ec
Show file tree
Hide file tree
Showing 45 changed files with 192 additions and 190 deletions.
14 changes: 7 additions & 7 deletions lib/postgrex/extensions/array.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ defmodule Postgrex.Extensions.Array do

def decode(_) do
quote location: :keep do
<<len::int32, binary::binary-size(len)>>, [oid], [type] ->
<<ndims::int32, _has_null::int32, ^oid::uint32, dims::size(ndims)-binary-unit(64),
<<len::int32(), binary::binary-size(len)>>, [oid], [type] ->
<<ndims::int32(), _has_null::int32(), ^oid::uint32(), dims::size(ndims)-binary-unit(64),
data::binary>> = binary

# decode_list/2 defined by TypeModule
Expand All @@ -45,14 +45,14 @@ defmodule Postgrex.Extensions.Array do
# While libpq will decode an payload encoded for a 0-dim array, CockroachDB will not.
# Also, this is how libpq actually encodes 0-dim arrays.
def encode([], elem_oid, _encoder) do
<<20::int32, 1::int32, 0::int32, elem_oid::uint32, 0::int32, 1::int32>>
<<20::int32(), 1::int32(), 0::int32(), elem_oid::uint32(), 0::int32(), 1::int32()>>
end

def encode(list, elem_oid, encoder) do
{data, ndims, lengths} = encode(list, 0, [], encoder)
lengths = for len <- Enum.reverse(lengths), do: <<len::int32, 1::int32>>
iodata = [<<ndims::int32, 0::int32, elem_oid::uint32>>, lengths, data]
[<<IO.iodata_length(iodata)::int32>> | iodata]
lengths = for len <- Enum.reverse(lengths), do: <<len::int32(), 1::int32()>>
iodata = [<<ndims::int32(), 0::int32(), elem_oid::uint32()>>, lengths, data]
[<<IO.iodata_length(iodata)::int32()>> | iodata]
end

defp encode([], ndims, lengths, _encoder) do
Expand Down Expand Up @@ -96,7 +96,7 @@ defmodule Postgrex.Extensions.Array do
end
end

defp decode_dims(<<len::int32, _lbound::int32, rest::binary>>, acc) do
defp decode_dims(<<len::int32(), _lbound::int32(), rest::binary>>, acc) do
decode_dims(rest, [len | acc])
end

Expand Down
10 changes: 5 additions & 5 deletions lib/postgrex/extensions/bit_string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Postgrex.Extensions.BitString do
def encode(_) do
quote location: :keep, generated: true do
val when is_binary(val) ->
[<<byte_size(val) + 4::int32, bit_size(val)::uint32>> | val]
[<<byte_size(val) + 4::int32(), bit_size(val)::uint32()>> | val]

val when is_bitstring(val) ->
bin_size = byte_size(val)
Expand All @@ -18,7 +18,7 @@ defmodule Postgrex.Extensions.BitString do
bit_count = bit_size(val)

[
<<bin_size + 4::int32, bit_count::uint32>>,
<<bin_size + 4::int32(), bit_count::uint32()>>,
binary
| <<last::bits, 0::size(pad)>>
]
Expand All @@ -30,7 +30,7 @@ defmodule Postgrex.Extensions.BitString do

def decode(:copy) do
quote location: :keep do
<<len::int32, value::binary-size(len)>> ->
<<len::int32(), value::binary-size(len)>> ->
copy = :binary.copy(value)
<<len::unsigned-32, bits::bits-size(len), _::bits>> = copy
bits
Expand All @@ -39,8 +39,8 @@ defmodule Postgrex.Extensions.BitString do

def decode(:reference) do
quote location: :keep do
<<len::int32, value::binary-size(len)>> ->
<<len::int32, bits::bits-size(len), _::bits>> = value
<<len::int32(), value::binary-size(len)>> ->
<<len::int32(), bits::bits-size(len), _::bits>> = value
bits
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/postgrex/extensions/bool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ defmodule Postgrex.Extensions.Bool do
def encode(_) do
quote location: :keep do
true ->
<<1::int32, 1>>
<<1::int32(), 1>>

false ->
<<1::int32, 0>>
<<1::int32(), 0>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, "a boolean")
Expand All @@ -18,8 +18,8 @@ defmodule Postgrex.Extensions.Bool do

def decode(_) do
quote location: :keep do
<<1::int32, 1>> -> true
<<1::int32, 0>> -> false
<<1::int32(), 1>> -> true
<<1::int32(), 0>> -> false
end
end
end
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/box.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Postgrex.Extensions.Box do
encoded_p1 = Point.encode_point(p1, Postgrex.Box)
encoded_p2 = Point.encode_point(p2, Postgrex.Box)
# 2 points -> 16 bytes each
[<<32::int32>>, encoded_p1 | encoded_p2]
[<<32::int32()>>, encoded_p1 | encoded_p2]

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Line)
Expand All @@ -20,7 +20,7 @@ defmodule Postgrex.Extensions.Box do
def decode(_) do
quote location: :keep do
# 2 points -> 16 bytes each
<<32::int32, x1::float64, y1::float64, x2::float64, y2::float64>> ->
<<32::int32(), x1::float64(), y1::float64(), x2::float64(), y2::float64()>> ->
p1 = %Postgrex.Point{x: x1, y: y1}
p2 = %Postgrex.Point{x: x2, y: y2}
%Postgrex.Box{upper_right: p1, bottom_left: p2}
Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/circle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Postgrex.Extensions.Circle do
quote location: :keep do
%Postgrex.Circle{center: %Postgrex.Point{x: x, y: y}, radius: r}
when is_number(x) and is_number(y) and is_number(r) and r >= 0 ->
<<24::int32, x::float64, y::float64, r::float64>>
<<24::int32(), x::float64(), y::float64(), r::float64()>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Path)
Expand All @@ -16,7 +16,7 @@ defmodule Postgrex.Extensions.Circle do

def decode(_) do
quote location: :keep do
<<24::int32, x::float64, y::float64, r::float64>> ->
<<24::int32(), x::float64(), y::float64(), r::float64()>> ->
%Postgrex.Circle{center: %Postgrex.Point{x: x, y: y}, radius: r}
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/date.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ defmodule Postgrex.Extensions.Date do

def decode(_) do
quote location: :keep do
<<4::int32, days::int32>> ->
<<4::int32(), days::int32()>> ->
unquote(__MODULE__).day_to_elixir(days)
end
end

## Helpers

def encode_elixir(%Date{year: year} = date) when year <= @max_year do
<<4::int32, Date.to_gregorian_days(date) - @gd_epoch::int32>>
<<4::int32(), Date.to_gregorian_days(date) - @gd_epoch::int32()>>
end

def encode_elixir(%Date{} = date) do
Expand Down
16 changes: 8 additions & 8 deletions lib/postgrex/extensions/float4.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ defmodule Postgrex.Extensions.Float4 do
def encode(_) do
quote location: :keep do
n when is_number(n) ->
<<4::int32, n::float32>>
<<4::int32(), n::float32()>>

:NaN ->
<<4::int32, 0::1, 255, 1::1, 0::22>>
<<4::int32(), 0::1, 255, 1::1, 0::22>>

:inf ->
<<4::int32, 0::1, 255, 0::23>>
<<4::int32(), 0::1, 255, 0::23>>

:"-inf" ->
<<4::int32, 1::1, 255, 0::23>>
<<4::int32(), 1::1, 255, 0::23>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, "a float")
Expand All @@ -24,10 +24,10 @@ defmodule Postgrex.Extensions.Float4 do

def decode(_) do
quote location: :keep do
<<4::int32, 0::1, 255, 0::23>> -> :inf
<<4::int32, 1::1, 255, 0::23>> -> :"-inf"
<<4::int32, _::1, 255, _::23>> -> :NaN
<<4::int32, float::float32>> -> float
<<4::int32(), 0::1, 255, 0::23>> -> :inf
<<4::int32(), 1::1, 255, 0::23>> -> :"-inf"
<<4::int32(), _::1, 255, _::23>> -> :NaN
<<4::int32(), float::float32()>> -> float
end
end
end
16 changes: 8 additions & 8 deletions lib/postgrex/extensions/float8.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ defmodule Postgrex.Extensions.Float8 do
def encode(_) do
quote location: :keep do
n when is_number(n) ->
<<8::int32, n::float64>>
<<8::int32(), n::float64()>>

:NaN ->
<<8::int32, 0::1, 2047::11, 1::1, 0::51>>
<<8::int32(), 0::1, 2047::11, 1::1, 0::51>>

:inf ->
<<8::int32, 0::1, 2047::11, 0::52>>
<<8::int32(), 0::1, 2047::11, 0::52>>

:"-inf" ->
<<8::int32, 1::1, 2047::11, 0::52>>
<<8::int32(), 1::1, 2047::11, 0::52>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, "a float")
Expand All @@ -24,10 +24,10 @@ defmodule Postgrex.Extensions.Float8 do

def decode(_) do
quote location: :keep do
<<8::int32, 0::1, 2047::11, 0::52>> -> :inf
<<8::int32, 1::1, 2047::11, 0::52>> -> :"-inf"
<<8::int32, _::1, 2047::11, _::52>> -> :NaN
<<8::int32, float::float64>> -> float
<<8::int32(), 0::1, 2047::11, 0::52>> -> :inf
<<8::int32(), 1::1, 2047::11, 0::52>> -> :"-inf"
<<8::int32(), _::1, 2047::11, _::52>> -> :NaN
<<8::int32(), float::float64()>> -> float
end
end
end
22 changes: 11 additions & 11 deletions lib/postgrex/extensions/hstore.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Postgrex.Extensions.HStore do
quote location: :keep do
%{} = map ->
data = unquote(__MODULE__).encode_hstore(map)
[<<IO.iodata_length(data)::int32>> | data]
[<<IO.iodata_length(data)::int32()>> | data]

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, "a map")
Expand All @@ -18,7 +18,7 @@ defmodule Postgrex.Extensions.HStore do

def decode(mode) do
quote do
<<len::int32, data::binary-size(len)>> ->
<<len::int32(), data::binary-size(len)>> ->
unquote(__MODULE__).decode_hstore(data, unquote(mode))
end
end
Expand All @@ -31,7 +31,7 @@ defmodule Postgrex.Extensions.HStore do
[acc, encode_hstore_key(key), encode_hstore_value(value)]
end)

[<<map_size(hstore_map)::int32>> | keys_and_values]
[<<map_size(hstore_map)::int32()>> | keys_and_values]
end

defp encode_hstore_key(key) when is_binary(key) do
Expand All @@ -43,19 +43,19 @@ defmodule Postgrex.Extensions.HStore do
end

defp encode_hstore_value(nil) do
<<-1::int32>>
<<-1::int32()>>
end

defp encode_hstore_value(value) when is_binary(value) do
value_byte_size = byte_size(value)
<<value_byte_size::int32>> <> value
<<value_byte_size::int32()>> <> value
end

def decode_hstore(<<_length::int32, pairs::binary>>, :reference) do
def decode_hstore(<<_length::int32(), pairs::binary>>, :reference) do
decode_hstore_ref(pairs, %{})
end

def decode_hstore(<<_length::int32, pairs::binary>>, :copy) do
def decode_hstore(<<_length::int32(), pairs::binary>>, :copy) do
decode_hstore_copy(pairs, %{})
end

Expand All @@ -65,14 +65,14 @@ defmodule Postgrex.Extensions.HStore do

# in the case of a NULL value, there won't be a length
defp decode_hstore_ref(
<<key_length::int32, key::binary(key_length), -1::int32, rest::binary>>,
<<key_length::int32(), key::binary(key_length), -1::int32(), rest::binary>>,
acc
) do
decode_hstore_ref(rest, Map.put(acc, key, nil))
end

defp decode_hstore_ref(
<<key_length::int32, key::binary(key_length), value_length::int32,
<<key_length::int32(), key::binary(key_length), value_length::int32(),
value::binary(value_length), rest::binary>>,
acc
) do
Expand All @@ -85,14 +85,14 @@ defmodule Postgrex.Extensions.HStore do

# in the case of a NULL value, there won't be a length
defp decode_hstore_copy(
<<key_length::int32, key::binary(key_length), -1::int32, rest::binary>>,
<<key_length::int32(), key::binary(key_length), -1::int32(), rest::binary>>,
acc
) do
decode_hstore_copy(rest, Map.put(acc, :binary.copy(key), nil))
end

defp decode_hstore_copy(
<<key_length::int32, key::binary(key_length), value_length::int32,
<<key_length::int32(), key::binary(key_length), value_length::int32(),
value::binary(value_length), rest::binary>>,
acc
) do
Expand Down
12 changes: 6 additions & 6 deletions lib/postgrex/extensions/inet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ defmodule Postgrex.Extensions.INET do
def encode(_) do
quote location: :keep do
%Postgrex.INET{address: {a, b, c, d}, netmask: nil} ->
<<8::int32, 2, 32, 0, 4, a, b, c, d>>
<<8::int32(), 2, 32, 0, 4, a, b, c, d>>

%Postgrex.INET{address: {a, b, c, d}, netmask: n} ->
<<8::int32, 2, n, 1, 4, a, b, c, d>>
<<8::int32(), 2, n, 1, 4, a, b, c, d>>

%Postgrex.INET{address: {a, b, c, d, e, f, g, h}, netmask: nil} ->
<<20::int32, 3, 128, 0, 16, a::16, b::16, c::16, d::16, e::16, f::16, g::16, h::16>>
<<20::int32(), 3, 128, 0, 16, a::16, b::16, c::16, d::16, e::16, f::16, g::16, h::16>>

%Postgrex.INET{address: {a, b, c, d, e, f, g, h}, netmask: n} ->
<<20::int32, 3, n, 1, 16, a::16, b::16, c::16, d::16, e::16, f::16, g::16, h::16>>
<<20::int32(), 3, n, 1, 16, a::16, b::16, c::16, d::16, e::16, f::16, g::16, h::16>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.INET)
Expand All @@ -25,11 +25,11 @@ defmodule Postgrex.Extensions.INET do

def decode(_) do
quote location: :keep do
<<8::int32, 2, n, cidr?, 4, a, b, c, d>> ->
<<8::int32(), 2, n, cidr?, 4, a, b, c, d>> ->
n = if(cidr? == 1 or n != 32, do: n, else: nil)
%Postgrex.INET{address: {a, b, c, d}, netmask: n}

<<20::int32, 3, n, cidr?, 16, a::16, b::16, c::16, d::16, e::16, f::16, g::16, h::16>> ->
<<20::int32(), 3, n, cidr?, 16, a::16, b::16, c::16, d::16, e::16, f::16, g::16, h::16>> ->
n = if(cidr? == 1 or n != 128, do: n, else: nil)
%Postgrex.INET{address: {a, b, c, d, e, f, g, h}, netmask: n}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/int2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Postgrex.Extensions.Int2 do

quote location: :keep do
int when is_integer(int) and int in unquote(range) ->
<<2::int32, int::int16>>
<<2::int32(), int::int16()>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, unquote(range))
Expand All @@ -19,7 +19,7 @@ defmodule Postgrex.Extensions.Int2 do

def decode(_) do
quote location: :keep do
<<2::int32, int::int16>> -> int
<<2::int32(), int::int16()>> -> int
end
end
end
4 changes: 2 additions & 2 deletions lib/postgrex/extensions/int4.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Postgrex.Extensions.Int4 do

quote location: :keep do
int when is_integer(int) and int in unquote(range) ->
<<4::int32, int::int32>>
<<4::int32(), int::int32()>>

other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, unquote(range))
Expand All @@ -19,7 +19,7 @@ defmodule Postgrex.Extensions.Int4 do

def decode(_) do
quote location: :keep do
<<4::int32, int::int32>> -> int
<<4::int32(), int::int32()>> -> int
end
end
end
Loading

0 comments on commit 8e4f0ec

Please sign in to comment.