Skip to content

Commit 07e580c

Browse files
committed
Keep line number in cond_clause error (#9730)
1 parent 1f9f713 commit 07e580c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/elixir/src/elixir_erl_pass.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ translate({'cond', CondMeta, [[{do, Clauses}]]}, S) ->
126126
true -> Meta
127127
end,
128128

129-
Error = {{'.', Meta, [erlang, error]}, [], [cond_clause]},
129+
Error = {{'.', Meta, [erlang, error]}, Meta, [cond_clause]},
130130
{Case, SC} = build_cond_clauses([H | T], Error, FirstMeta, S),
131131
translate(replace_case_meta(CondMeta, Case), SC);
132132

lib/elixir/test/elixir/kernel/special_forms_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,20 @@ defmodule Kernel.SpecialFormsTest do
5252
:otherwise -> :also_good
5353
end
5454
end
55+
56+
def false_fun(), do: false
57+
58+
test "cond_clause error keeps line number in stacktrace" do
59+
try do
60+
cond do
61+
false_fun() -> :ok
62+
end
63+
rescue
64+
_ ->
65+
assert [{Kernel.SpecialFormsTest, _, _, meta} | _] = __STACKTRACE__
66+
assert meta[:file]
67+
assert meta[:line]
68+
end
69+
end
5570
end
5671
end

0 commit comments

Comments
 (0)