Skip to content

Commit 1ae36fa

Browse files
committed
Keep expression when normalizing is_struct in blame
Closes #12243.
1 parent e3fc947 commit 1ae36fa

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/elixir/lib/exception.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,11 @@ defmodule Exception do
294294
end
295295
end
296296

297-
defp undo_is_struct_guard(
298-
{:and, meta, [_, %{node: {_, _, [{_, _, [_, {struct, _, _}]} | optional]}}]}
299-
) do
297+
defp undo_is_struct_guard({:and, meta, [_, %{node: {_, _, [{_, _, [_, arg]} | optional]}}]}) do
300298
args =
301299
case optional do
302-
[] -> [{struct, meta, nil}]
303-
[module] -> [{struct, meta, nil}, module]
300+
[] -> [arg]
301+
[module] -> [arg, module]
304302
end
305303

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

lib/elixir/test/elixir/exception_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ defmodule ExceptionTest do
426426
when is_binary(url) or (is_struct(url) and is_struct(url, url_module) and false) do
427427
url
428428
end
429+
430+
def sub_get!(url) when is_struct(url.sub, URI), do: url.sub
429431
end
430432
)
431433

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

480495
test "annotates badarg on apply" do

0 commit comments

Comments
 (0)