Improve send return types#15644
Conversation
cd06baa to
91c4ec8
Compare
| end | ||
|
|
||
| defp remote_apply(:erlang, :send, _info, [_dest, message] = args_types, stack) do | ||
| {:ok, return(message, args_types, stack)} |
There was a problem hiding this comment.
I am almost sure you still need to call remote_apply/3 to validate the argument types. In particular the first arg. See Map.from_struct typing as an example.
There was a problem hiding this comment.
Good catch. I now call the generic remote_apply/3 first and only replace the validated return type with the message type on success.
| test "send returns the message" do | ||
| assert typecheck!(send(self(), {:msg, 1})) == tuple([atom([:msg]), integer()]) | ||
|
|
||
| assert typeerror!( |
There was a problem hiding this comment.
This test is redundant. Instead we should test that we validate the first argument and emit an error otherwise.
There was a problem hiding this comment.
Updated. I removed the redundant direct return assertion and added coverage that send/2 rejects an invalid destination.
There was a problem hiding this comment.
You changed the wrong one. You should change the line commented, the previous positive assertion was good and should be kept.
There was a problem hiding this comment.
Correction: I had misread which assertion the comment referred to. The positive return-type assertion is restored, and only the redundant never-match diagnostic assertion was replaced with invalid-destination coverage.
91c4ec8 to
42b7508
Compare
Teach the type checker that Kernel.send/2 returns the message operand. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
42b7508 to
019e691
Compare
|
💚 💙 💜 💛 ❤️ |
Teach the type checker that
Kernel.send/2returns the message operand and add a typed signature for:erlang.send/3status returns.AssistedBy: GPT 5.5