Skip to content

Commit c5269a5

Browse files
authored
Typespecs: show expanded module name on inexistent struct field error (#11353)
Closes #11352.
1 parent a620e9e commit c5269a5

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ defmodule Kernel.Typespec do
575575
unless Keyword.has_key?(struct, field) do
576576
compile_error(
577577
caller,
578-
"undefined field #{inspect(field)} on struct #{Macro.to_string(name)}"
578+
"undefined field #{inspect(field)} on struct #{inspect(module)}"
579579
)
580580
end
581581
end

lib/elixir/test/elixir/typespec_test.exs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,23 @@ defmodule TypespecTest do
521521
end
522522

523523
test "@type with a struct with undefined field" do
524-
assert_raise CompileError, ~r"undefined field :no_field on struct TypespecSample", fn ->
525-
test_module do
526-
defstruct [:hello, :eric]
527-
@type my_type :: %TypespecSample{no_field: :world}
528-
end
529-
end
524+
assert_raise CompileError,
525+
~r"undefined field :no_field on struct TypespecTest.TypespecSample",
526+
fn ->
527+
test_module do
528+
defstruct [:hello, :eric]
529+
@type my_type :: %TypespecSample{no_field: :world}
530+
end
531+
end
532+
533+
assert_raise CompileError,
534+
~r"undefined field :no_field on struct TypespecTest.TypespecSample",
535+
fn ->
536+
test_module do
537+
defstruct [:hello, :eric]
538+
@type my_type :: %__MODULE__{no_field: :world}
539+
end
540+
end
530541
end
531542

532543
test "@type when overriding Elixir built-in" do

0 commit comments

Comments
 (0)