Skip to content

Commit 0e9cb57

Browse files
committed
Keep expression when normalizing is_struct in blame
Closes #12243.
1 parent 88ce2c7 commit 0e9cb57

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/elixir/lib/exception.ex

+3-5
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,11 @@ defmodule Exception do
291291
end
292292
end
293293

294-
defp undo_is_struct_guard(
295-
{:and, meta, [_, %{node: {_, _, [{_, _, [_, {struct, _, _}]} | optional]}}]}
296-
) do
294+
defp undo_is_struct_guard({:and, meta, [_, %{node: {_, _, [{_, _, [_, arg]} | optional]}}]}) do
297295
args =
298296
case optional do
299-
[] -> [{struct, meta, nil}]
300-
[module] -> [{struct, meta, nil}, module]
297+
[] -> [arg]
298+
[module] -> [arg, module]
301299
end
302300

303301
%{match?: meta[:value], node: {:is_struct, meta, args}}

lib/elixir/test/elixir/exception_test.exs

+15
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ defmodule ExceptionTest do
428428
when is_binary(url) or (is_struct(url) and is_struct(url, url_module) and false) do
429429
url
430430
end
431+
432+
def sub_get!(url) when is_struct(url.sub, URI), do: url.sub
431433
end
432434
)
433435

@@ -477,6 +479,19 @@ defmodule ExceptionTest do
477479
478480
def get!(url) when -is_binary(url)- or is_struct(url) and is_struct(url, URI) and -false-
479481
"""
482+
483+
assert blame_message(Req, & &1.sub_get!(%{})) =~ """
484+
no function clause matching in ExceptionTest.Req.sub_get!/1
485+
486+
The following arguments were given to ExceptionTest.Req.sub_get!/1:
487+
488+
# 1
489+
%{}
490+
491+
Attempted function clauses (showing 1 out of 1):
492+
493+
def sub_get!(url) when -is_struct(url.sub, URI)-
494+
"""
480495
end
481496

482497
test "annotates badarg on apply" do

0 commit comments

Comments
 (0)