Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/elixir/lib/module/types/apply.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ defmodule Module.Types.Apply do
|> opt_union(atom())
|> opt_union(tuple([atom(), atom()]))

send_options = list(atom([:noconnect, :nosuspend]))
send_result = atom([:ok, :noconnect, :nosuspend])

basic_arith_2_args_clauses = [
{[integer(), integer()], integer()},
{[integer(), float()], float()},
Expand Down Expand Up @@ -239,6 +242,7 @@ defmodule Module.Types.Apply do
{:erlang, :max, [{[term(), term()], dynamic()}]},
{:erlang, :min, [{[term(), term()], dynamic()}]},
{:erlang, :send, [{[send_destination, term()], dynamic()}]},
{:erlang, :send, [{[send_destination, term(), send_options], send_result}]},
{:erlang, :setelement, [{[integer(), open_tuple([]), term()], dynamic(open_tuple([]))}]},
{:erlang, :tl, [{[non_empty_list(term(), term())], dynamic()}]},
{:erlang, :tuple_to_list, [{[open_tuple([])], dynamic(list(term()))}]},
Expand Down Expand Up @@ -1099,6 +1103,10 @@ defmodule Module.Types.Apply do
end
end

defp remote_apply(:erlang, :send, _info, [_dest, message] = args_types, stack) do
{:ok, return(message, args_types, stack)}
end

defp remote_apply(:erlang, :tl, _info, [list], stack) do
case list_tl(list) do
{:ok, value_type} -> {:ok, return(value_type, [list], stack)}
Expand Down
30 changes: 30 additions & 0 deletions lib/elixir/test/elixir/module/types/expr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,36 @@ defmodule Module.Types.ExprTest do
) == dynamic(tuple([integer(), integer(), binary()]))
end

test "send returns the message" do
assert typecheck!(send(self(), {:msg, 1})) == tuple([atom([:msg]), integer()])

assert typeerror!(
case send(self(), {:msg, 1}) do
:__probe__ -> :probe
_ -> :ok
end
) == ~l"""
the following clause will never match:

:__probe__ ->

because it attempts to match on the result of:

send(self(), {:msg, 1})

which has type:

{:msg, integer()}
"""
end

test "send with options returns status" do
result = atom([:ok, :noconnect, :nosuspend])

assert typecheck!(:erlang.send(self(), {:msg, 1}, [:nosuspend])) == result
assert typecheck!(Process.send(self(), {:msg, 1}, [:noconnect])) == result
end

test "undefined function warnings" do
assert typewarn!(URI.unknown("foo")) ==
{dynamic(), "URI.unknown/1 is undefined or private"}
Expand Down