Skip to content

Commit 7f494e6

Browse files
committed
Fix signature order in type checkings messages, closes #11744
1 parent 41fa1db commit 7f494e6

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lib/elixir/lib/module/types.ex

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,21 @@ defmodule Module.Types do
211211
## FORMAT WARNINGS
212212

213213
def format_warning({:unable_apply, mfa, args, expected, signature, {location, expr, traces}}) do
214-
{module, function, arity} = mfa
215-
mfa_args = Macro.generate_arguments(arity, __MODULE__)
216-
{module, function, ^arity} = call_to_mfa(erl_to_ex(module, function, mfa_args, []))
214+
{original_module, original_function, arity} = mfa
215+
{_, _, args} = mfa_or_fa = erl_to_ex(original_module, original_function, args, [])
216+
{module, function, ^arity} = call_to_mfa(mfa_or_fa)
217217
format_mfa = Exception.format_mfa(module, function, arity)
218218
{traces, [] = _hints} = format_traces(traces, [], false)
219219

220220
clauses =
221-
Enum.map(
222-
signature,
223-
&String.slice(IO.iodata_to_binary(Unify.format_type({:fun, [&1]}, false)), 1..-2)
224-
)
221+
Enum.map(signature, fn {ins, out} ->
222+
{_, _, ins} = erl_to_ex(original_module, original_function, ins, [])
223+
224+
{:fun, [{ins, out}]}
225+
|> Unify.format_type(false)
226+
|> IO.iodata_to_binary()
227+
|> binary_slice(1..-2//1)
228+
end)
225229

226230
[
227231
"expected #{format_mfa} to have signature:\n\n ",

lib/elixir/test/elixir/module/types/types_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,25 @@ defmodule Module.Types.TypesTest do
357357
foo - :bar
358358
"""
359359
end
360+
361+
test "rewrite call" do
362+
string = warning([foo], [is_map_key(1, foo)], foo)
363+
364+
assert string == """
365+
expected Kernel.is_map_key/2 to have signature:
366+
367+
integer(), var1 -> dynamic()
368+
369+
but it has signature:
370+
371+
%{optional(dynamic()) => dynamic()}, dynamic() -> dynamic()
372+
373+
in expression:
374+
375+
# types_test.ex:1
376+
is_map_key(1, foo)
377+
"""
378+
end
360379
end
361380

362381
describe "map warnings" do

0 commit comments

Comments
 (0)