Skip to content

Commit af7c8ef

Browse files
committed
Simplify format pruning and keep columns
1 parent bbbf3c9 commit af7c8ef

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

lib/elixir/lib/module/types/helpers.ex

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ defmodule Module.Types.Helpers do
130130

131131
%{
132132
file: file,
133-
meta: meta,
133+
line: meta[:line],
134+
column: meta[:column],
135+
hints: formatter_hints ++ expr_hints(expr),
134136
formatted_expr: formatted_expr,
135-
formatted_hints: format_hints(formatter_hints ++ expr_hints(expr)),
136137
formatted_type: Module.Types.Descr.to_quoted_string(type)
137138
}
138139
end)
139-
|> Enum.sort_by(&{&1.meta[:line], &1.meta[:column]})
140+
|> Enum.sort_by(&{&1.line, &1.column})
141+
|> Enum.dedup()
140142
end
141143

142144
@doc """
@@ -148,30 +150,25 @@ defmodule Module.Types.Helpers do
148150

149151
defp format_trace(%{type: :variable, name: name, context: context, traces: traces}) do
150152
traces =
151-
traces
152-
|> Enum.map(fn trace ->
153+
for trace <- traces do
153154
location =
154155
trace.file
155156
|> Path.relative_to_cwd()
156-
|> Exception.format_file_line(trace.meta[:line])
157+
|> Exception.format_file_line(trace.line, trace.column)
157158
|> String.replace_suffix(":", "")
158159

159-
{trace.formatted_type, location, trace.formatted_expr, trace.formatted_hints}
160-
end)
161-
|> Enum.dedup()
162-
|> Enum.map(fn {formatted_type, location, formatted_expr, formatted_hints} ->
163160
[
164161
"""
165162
166-
# type: #{indent(formatted_type, 4)}
163+
# type: #{indent(trace.formatted_type, 4)}
167164
# from: #{location}
168165
\
169166
""",
170-
indent(formatted_expr, 4),
167+
indent(trace.formatted_expr, 4),
171168
?\n,
172-
formatted_hints
169+
format_hints(trace.hints)
173170
]
174-
end)
171+
end
175172

176173
type_or_types = pluralize(traces, "type", "types")
177174
["\nwhere #{format_var(name, context)} was given the #{type_or_types}:\n" | traces]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ defmodule Module.Types.ExprTest do
572572
scheme: term(),
573573
userinfo: term()
574574
})
575-
# from: types_test.ex:LINE-4
575+
# from: types_test.ex:LINE-4:41
576576
x = %URI{}
577577
"""
578578

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ defmodule TypeHelper do
3232
Main helper for checking the given AST type checks errors.
3333
"""
3434
defmacro typeerror!(patterns \\ [], guards \\ true, body) do
35+
[patterns, guards, body] = prune_columns([patterns, guards, body])
36+
3537
quote do
3638
unquote(typecheck(patterns, guards, body, __CALLER__))
3739
|> TypeHelper.__typeerror__!()
@@ -42,6 +44,8 @@ defmodule TypeHelper do
4244
Main helper for checking the given AST type warns.
4345
"""
4446
defmacro typewarn!(patterns \\ [], guards \\ true, body) do
47+
[patterns, guards, body] = prune_columns([patterns, guards, body])
48+
4549
quote do
4650
unquote(typecheck(patterns, guards, body, __CALLER__))
4751
|> TypeHelper.__typewarn__!()
@@ -204,4 +208,10 @@ defmodule TypeHelper do
204208

205209
IO.iodata_to_binary([head | rest])
206210
end
211+
212+
defp prune_columns(ast) do
213+
Macro.prewalk(ast, fn node ->
214+
Macro.update_meta(node, &Keyword.delete(&1, :column))
215+
end)
216+
end
207217
end

0 commit comments

Comments
 (0)