Skip to content

Commit e855a85

Browse files
author
José Valim
committed
Merge branch 'issue-2022-warnings' of github.com:ShaneWilton/elixir into ShaneWilton-issue-2022-warnings
Conflicts: lib/elixir/test/elixir/kernel/warning_test.exs lib/iex/test/iex/helpers_test.exs
2 parents b9c49c9 + 36d1dcd commit e855a85

File tree

5 files changed

+47
-42
lines changed

5 files changed

+47
-42
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ defmodule Kernel.Typespec do
298298
if export do
299299
Module.add_doc(module, caller.line, kind, { name, arity }, doc)
300300
else
301-
:elixir_errors.warn "#{caller.file}:#{caller.line}: type #{name}/#{arity} is private, " <>
301+
:elixir_errors.warn caller.line, caller.file, "type #{name}/#{arity} is private, " <>
302302
"@typedoc's are always discarded for private types\n"
303303
end
304304
end
@@ -848,7 +848,7 @@ defmodule Kernel.Typespec do
848848

849849
# Handle local calls
850850
defp typespec({:string, meta, arguments}, vars, caller) do
851-
:elixir_errors.warn "warning: string() type use is discouraged. For character lists, use " <>
851+
:elixir_errors.warn caller.line, caller.file, "string() type use is discouraged. For character lists, use " <>
852852
"char_list() type, for strings, String.t()\n#{Exception.format_stacktrace(caller.stacktrace)}"
853853
arguments = lc arg inlist arguments, do: typespec(arg, vars, caller)
854854
{ :type, line(meta), :string, arguments }

lib/elixir/lib/module.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ defmodule Module do
778778
:lists.member(key, acc) ->
779779
[]
780780
is_list(warn) ->
781-
:elixir_errors.warn "#{Exception.format_caller(warn)} undefined module attribute @#{key}, " <>
781+
:elixir_errors.warn Exception.format_caller(warn), "undefined module attribute @#{key}, " <>
782782
"please remove access to @#{key} or explicitly set it to nil before access\n"
783783
nil
784784
true ->
@@ -877,7 +877,7 @@ defmodule Module do
877877
:ok ->
878878
:ok
879879
{ :error, :private_doc } ->
880-
:elixir_errors.warn "#{env.file}:#{line} function #{name}/#{arity} is private, @doc's are always discarded for private functions\n"
880+
:elixir_errors.warn line, env.file, "function #{name}/#{arity} is private, @doc's are always discarded for private functions\n"
881881
end
882882
883883
delete_attribute(module, :doc)

lib/elixir/src/elixir_errors.erl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
% This is not exposed in the Elixir language.
33
-module(elixir_errors).
44
-export([compile_error/3, compile_error/4,
5-
form_error/4, parse_error/4, warn/1,
5+
form_error/4, parse_error/4, warn/2, warn/3,
66
handle_file_warning/2, handle_file_warning/3, handle_file_error/2,
77
deprecation/3, deprecation/4]).
88
-include("elixir.hrl").
@@ -16,6 +16,12 @@ warn(Warning) ->
1616
end,
1717
io:put_chars(standard_error, Warning).
1818

19+
warn(Caller, Warning) ->
20+
warn([Caller, " warning: ", Warning]).
21+
22+
warn(Line, File, Warning) ->
23+
warn(file_format(Line, File, "warning: " ++ Warning)).
24+
1925
%% Raised during expansion/translation/compilation.
2026

2127
-spec form_error(list(), binary(), module(), any()) -> no_return().
@@ -93,7 +99,7 @@ handle_file_warning(_, File, { Line, sys_core_fold, { no_effect, { erlang, F, A
9399
end
94100
end,
95101
Message = io_lib:format(Fmt, Args),
96-
warn(file_format(Line, File, Message));
102+
warn(Line, File, Message);
97103

98104
%% Rewrite undefined behaviour to check for protocols
99105
handle_file_warning(_, File, {Line,erl_lint,{undefined_behaviour_func,{Fun,Arity},Module}}) ->
@@ -106,14 +112,14 @@ handle_file_warning(_, File, {Line,erl_lint,{undefined_behaviour_func,{Fun,Arity
106112
Kind = protocol_or_behaviour(Module),
107113
Raw = "undefined ~ts ~ts ~ts/~B (for ~ts ~ts)",
108114
Message = io_lib:format(Raw, [Kind, DefKind, Def, DefArity, Kind, elixir_aliases:inspect(Module)]),
109-
warn(file_format(Line, File, Message));
115+
warn(Line, File, Message);
110116

111117
handle_file_warning(_, File, {Line,erl_lint,{undefined_behaviour,Module}}) ->
112118
case elixir_compiler:get_opt(internal) of
113119
true -> [];
114120
false ->
115121
Message = io_lib:format("behaviour ~ts undefined", [elixir_aliases:inspect(Module)]),
116-
warn(file_format(Line, File, Message))
122+
warn(Line, File, Message)
117123
end;
118124

119125
%% Ignore unused vars at "weird" lines (<= 0)
@@ -127,12 +133,12 @@ handle_file_warning(_, _File, {_Line,erl_lint,{shadowed_var,_Var,_Where}}) ->
127133
%% Properly format other unused vars
128134
handle_file_warning(_, File, {Line,erl_lint,{unused_var,Var}}) ->
129135
Message = format_error(erl_lint, { unused_var, format_var(Var) }),
130-
warn(file_format(Line, File, Message));
136+
warn(Line, File, Message);
131137

132138
%% Default behaviour
133139
handle_file_warning(_, File, {Line,Module,Desc}) ->
134140
Message = format_error(Module, Desc),
135-
warn(file_format(Line, File, Message)).
141+
warn(Line, File, Message).
136142

137143
handle_file_warning(File, Desc) ->
138144
handle_file_warning(false, File, Desc).

lib/elixir/test/elixir/kernel/warning_test.exs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Kernel.WarningTest do
1717
def hello(arg), do: nil
1818
end
1919
"""
20-
end) =~ "variable arg is unused"
20+
end) =~ "warning: variable arg is unused"
2121
after
2222
purge Sample
2323
end
@@ -29,7 +29,7 @@ defmodule Kernel.WarningTest do
2929
defp hello, do: nil
3030
end
3131
"""
32-
end) =~ "function hello/0 is unused"
32+
end) =~ "warning: function hello/0 is unused"
3333

3434
assert capture_err(fn ->
3535
Code.eval_string """
@@ -49,7 +49,7 @@ defmodule Kernel.WarningTest do
4949
defp d(x), do: x
5050
end
5151
"""
52-
end) =~ "function c/2 is unused"
52+
end) =~ "warning: function c/2 is unused"
5353
after
5454
purge [Sample1, Sample2, Sample3]
5555
end
@@ -62,7 +62,7 @@ defmodule Kernel.WarningTest do
6262
defp b, do: a
6363
end
6464
"""
65-
end) =~ "function a/0 is unused"
65+
end) =~ "warning: function a/0 is unused"
6666
after
6767
purge Sample
6868
end
@@ -74,7 +74,7 @@ defmodule Kernel.WarningTest do
7474
defmacrop hello, do: nil
7575
end
7676
"""
77-
end) =~ "macro hello/0 is unused"
77+
end) =~ "warning: macro hello/0 is unused"
7878
after
7979
purge Sample
8080
end
@@ -104,7 +104,7 @@ defmodule Kernel.WarningTest do
104104
defp b(arg1 \\ 1, arg2 \\ 2, arg3 \\ 3), do: [arg1, arg2, arg3]
105105
end
106106
"""
107-
end) =~ "default arguments in b/3 are never used"
107+
end) =~ "warning: default arguments in b/3 are never used"
108108

109109
assert capture_err(fn ->
110110
Code.eval_string %S"""
@@ -113,7 +113,7 @@ defmodule Kernel.WarningTest do
113113
defp b(arg1 \\ 1, arg2 \\ 2, arg3 \\ 3), do: [arg1, arg2, arg3]
114114
end
115115
"""
116-
end) =~ "the first 2 default arguments in b/3 are never used"
116+
end) =~ "warning: the first 2 default arguments in b/3 are never used"
117117

118118
assert capture_err(fn ->
119119
Code.eval_string %S"""
@@ -122,7 +122,7 @@ defmodule Kernel.WarningTest do
122122
defp b(arg1 \\ 1, arg2 \\ 2, arg3 \\ 3), do: [arg1, arg2, arg3]
123123
end
124124
"""
125-
end) =~ "the first default argument in b/3 is never used"
125+
end) =~ "warning: the first default argument in b/3 is never used"
126126

127127
assert capture_err(fn ->
128128
Code.eval_string %S"""
@@ -144,13 +144,13 @@ defmodule Kernel.WarningTest do
144144
def a, do: nil
145145
end
146146
"""
147-
end) =~ "unused import :lists"
147+
end) =~ "warning: unused import :lists"
148148

149149
assert capture_err(fn ->
150150
Code.compile_string """
151151
import :lists, only: [flatten: 1]
152152
"""
153-
end) =~ "unused import :lists"
153+
end) =~ "warning: unused import :lists"
154154
after
155155
purge [Sample]
156156
end
@@ -163,7 +163,7 @@ defmodule Kernel.WarningTest do
163163
def a, do: nil
164164
end
165165
"""
166-
end) =~ "unused alias List"
166+
end) =~ "warning: unused alias List"
167167
after
168168
purge [Sample]
169169
end
@@ -179,7 +179,7 @@ defmodule Kernel.WarningTest do
179179
flatten([1,2,3])
180180
end
181181
end
182-
end) =~ "unused import String"
182+
end) =~ "warning: unused import String"
183183
after
184184
purge [Sample]
185185
end
@@ -197,7 +197,7 @@ defmodule Kernel.WarningTest do
197197
end
198198
end
199199
"""
200-
end) =~ "nofile:5: the guard for this clause evaluates to 'false'"
200+
end) =~ "nofile:5: warning: the guard for this clause evaluates to 'false'"
201201

202202
assert capture_err(fn ->
203203
Code.eval_string """
@@ -211,7 +211,7 @@ defmodule Kernel.WarningTest do
211211
end
212212
end
213213
"""
214-
end) =~ "nofile:6: this clause cannot match because a previous clause at line 5 always matches"
214+
end) =~ "nofile:6: warning: this clause cannot match because a previous clause at line 5 always matches"
215215
after
216216
purge [Sample1, Sample2]
217217
end
@@ -224,7 +224,7 @@ defmodule Kernel.WarningTest do
224224
def hello
225225
end
226226
"""
227-
end) =~ "empty clause provided for nonexistent function or macro hello/0"
227+
end) =~ "warning: empty clause provided for nonexistent function or macro hello/0"
228228
after
229229
purge [Sample1]
230230
end
@@ -258,7 +258,7 @@ defmodule Kernel.WarningTest do
258258
def hello, do: nil
259259
end
260260
"""
261-
end) =~ "this clause cannot match because a previous clause at line 2 always matches"
261+
end) =~ "warning: this clause cannot match because a previous clause at line 2 always matches"
262262
after
263263
purge Sample
264264
end
@@ -271,7 +271,7 @@ defmodule Kernel.WarningTest do
271271
def hello(arg \\ 0), do: nil
272272
end
273273
"""
274-
end) =~ "clause with defaults should be the first clause in def hello/1"
274+
end) =~ "warning: clause with defaults should be the first clause in def hello/1"
275275
after
276276
purge Sample
277277
end
@@ -286,7 +286,7 @@ defmodule Kernel.WarningTest do
286286
def hello, do: :ok
287287
end
288288
"""
289-
end) =~ "function world/0 is unused"
289+
end) =~ "warning: function world/0 is unused"
290290
after
291291
purge Sample
292292
end
@@ -312,7 +312,7 @@ defmodule Kernel.WarningTest do
312312
@foo
313313
end
314314
"""
315-
end) =~ "undefined module attribute @foo, please remove access to @foo or explicitly set it to nil before access"
315+
end) =~ "warning: undefined module attribute @foo, please remove access to @foo or explicitly set it to nil before access"
316316
after
317317
purge Sample
318318
end
@@ -326,15 +326,15 @@ defmodule Kernel.WarningTest do
326326
end
327327
end
328328
"""
329-
end) =~ "undefined module attribute @foo, please remove access to @foo or explicitly set it to nil before access"
329+
end) =~ "warning: undefined module attribute @foo, please remove access to @foo or explicitly set it to nil before access"
330330
after
331331
purge Sample
332332
end
333333

334334
test :undefined_module_attribute_with_file do
335335
assert capture_err(fn ->
336336
Code.load_file(fixture_path("attribute_warning.ex"))
337-
end) =~ "attribute_warning.ex:2: AttributeWarning (module) undefined module attribute @foo, please remove access to @foo or explicitly set it to nil before access"
337+
end) =~ "attribute_warning.ex:2: AttributeWarning (module) warning: undefined module attribute @foo, please remove access to @foo or explicitly set it to nil before access"
338338
after
339339
purge AttributeWarning
340340
end
@@ -346,7 +346,7 @@ defmodule Kernel.WarningTest do
346346
def a(x) when x in [], do: x
347347
end
348348
"""
349-
end) =~ "the guard for this clause evaluates to 'false'"
349+
end) =~ "warning: the guard for this clause evaluates to 'false'"
350350
after
351351
purge Sample
352352
end
@@ -361,7 +361,7 @@ defmodule Kernel.WarningTest do
361361
end
362362
end
363363
"""
364-
end) =~ "use of operator != has no effect"
364+
end) =~ "warning: use of operator != has no effect"
365365
after
366366
purge Sample
367367
end
@@ -378,7 +378,7 @@ defmodule Kernel.WarningTest do
378378
@behaviour Sample1
379379
end
380380
"""
381-
end) =~ "undefined behaviour function foo/0 (for behaviour Sample1)"
381+
end) =~ "warning: undefined behaviour function foo/0 (for behaviour Sample1)"
382382
after
383383
purge [Sample1, Sample2, Sample3]
384384
end
@@ -395,7 +395,7 @@ defmodule Kernel.WarningTest do
395395
@behaviour Sample1
396396
end
397397
"""
398-
end) =~ "undefined behaviour macro foo/0 (for behaviour Sample1)"
398+
end) =~ "warning: undefined behaviour macro foo/0 (for behaviour Sample1)"
399399
after
400400
purge [Sample1, Sample2, Sample3]
401401
end
@@ -410,7 +410,7 @@ defmodule Kernel.WarningTest do
410410
defimpl Sample1, for: Atom do
411411
end
412412
"""
413-
end) =~ "undefined protocol function foo/1 (for protocol Sample1)"
413+
end) =~ "warning: undefined protocol function foo/1 (for protocol Sample1)"
414414
after
415415
purge [Sample1, Sample1.Atom]
416416
end
@@ -424,7 +424,7 @@ defmodule Kernel.WarningTest do
424424
def foo(x, 2), do: x * 2
425425
end
426426
"""
427-
end) =~ "nofile:4: clauses for the same def should be grouped together, def foo/2 was previously defined (nofile:2)"
427+
end) =~ "nofile:4: warning: clauses for the same def should be grouped together, def foo/2 was previously defined (nofile:2)"
428428
after
429429
purge [Sample]
430430
end
@@ -437,7 +437,7 @@ defmodule Kernel.WarningTest do
437437
def foo(x), do: :ok
438438
end
439439
"""
440-
end) =~ "sample:3: variable x is unused"
440+
end) =~ "sample:3: warning: variable x is unused"
441441
after
442442
purge [Sample]
443443
end
@@ -452,7 +452,7 @@ defmodule Kernel.WarningTest do
452452
def foo(), do: nil
453453
end
454454
"""
455-
end) =~ "nofile:3: type priv/0 is private, @typedoc's are always discarded for private types"
455+
end) =~ "nofile:3: warning: type priv/0 is private, @typedoc's are always discarded for private types"
456456
after
457457
purge [Sample]
458458
end
@@ -464,7 +464,7 @@ defmodule Kernel.WarningTest do
464464
@typedoc "Something"
465465
end
466466
"""
467-
end) =~ "nofile:1: @typedoc provided but no type follows it"
467+
end) =~ "nofile:1: warning: @typedoc provided but no type follows it"
468468
after
469469
purge [Sample]
470470
end

lib/iex/test/iex/helpers_test.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ defmodule IEx.HelpersTest do
311311
assert_raise UndefinedFunctionError, "undefined function: Sample.run/0", fn ->
312312
Sample.run
313313
end
314-
315-
end) =~ %r"^.*?sample\.ex:1: redefining module Sample\n$"
314+
end) =~ %r"^.*?sample\.ex:1: warning: redefining module Sample\n$"
316315
end
317316
after
318317
# Clean up old version produced by the r helper

0 commit comments

Comments
 (0)