From b8599b0851f065f66541fa3d9e596868fe4b3469 Mon Sep 17 00:00:00 2001 From: Kiko Fernandez-Reyes Date: Tue, 14 Jan 2025 09:48:02 +0100 Subject: [PATCH] kernel: fixes socket.erl type spec the type specs for socker.erl were improved in PR-8986, but they introduced a bug by omitting one of the overloaded specs. this commit fixes that, and adds a test to check for it --- lib/dialyzer/test/small_SUITE_data/results/sock | 0 lib/dialyzer/test/small_SUITE_data/src/sock.erl | 17 +++++++++++++++++ lib/kernel/src/socket.erl | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lib/dialyzer/test/small_SUITE_data/results/sock create mode 100644 lib/dialyzer/test/small_SUITE_data/src/sock.erl diff --git a/lib/dialyzer/test/small_SUITE_data/results/sock b/lib/dialyzer/test/small_SUITE_data/results/sock new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/dialyzer/test/small_SUITE_data/src/sock.erl b/lib/dialyzer/test/small_SUITE_data/src/sock.erl new file mode 100644 index 000000000000..61bad8abbeb5 --- /dev/null +++ b/lib/dialyzer/test/small_SUITE_data/src/sock.erl @@ -0,0 +1,17 @@ +-module(sock). + +-export([sendto/4]). + +family({_,_,_,_}) -> inet; +family({_,_,_,_,_,_,_,_}) -> inet6. + +sendto(Socket, IP, Port, Data) -> + Dest = #{family => family(IP), + addr => IP, + port => Port}, + case socket:sendto(Socket, Data, Dest, nowait) of + ok -> ok; + Other -> + logger:debug("sendto(~p) failed with: ~p", [Dest, Other]), + ok + end. diff --git a/lib/kernel/src/socket.erl b/lib/kernel/src/socket.erl index 44b0c40f5d56..973a05047d6d 100644 --- a/lib/kernel/src/socket.erl +++ b/lib/kernel/src/socket.erl @@ -3763,7 +3763,9 @@ an explanation of `TimeoutOrHandle`. """. -spec sendto(Socket :: socket(), Data :: iodata(), - Dest :: sockaddr(), Flags :: list()) -> Result when + Dest :: sockaddr(), Flags | TimeoutOrHandle) -> Result when + TimeoutOrHandle :: dynamic(), + Flags :: list(), Result :: 'ok' | {'ok', RestData :: binary()} | {'error', Reason}