Skip to content

Commit 6b15b09

Browse files
committed
Remove line information from struct definitions, closes #13761
1 parent 4104bfc commit 6b15b09

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5455,21 +5455,33 @@ defmodule Kernel do
54555455
use `@type`.
54565456
"""
54575457
defmacro defstruct(fields) do
5458-
quote bind_quoted: [fields: fields, bootstrapped?: bootstrapped?(Enum)] do
5459-
{struct, derive, kv, body} =
5460-
Kernel.Utils.defstruct(__MODULE__, fields, bootstrapped?, __ENV__)
5458+
header =
5459+
quote bind_quoted: [fields: fields, bootstrapped?: bootstrapped?(Enum)] do
5460+
{struct, derive, kv, body} =
5461+
Kernel.Utils.defstruct(__MODULE__, fields, bootstrapped?, __ENV__)
5462+
5463+
case derive do
5464+
[] -> :ok
5465+
_ -> Protocol.__derive__(derive, __MODULE__, __ENV__)
5466+
end
5467+
end
54615468

5462-
case derive do
5463-
[] -> :ok
5464-
_ -> Protocol.__derive__(derive, __MODULE__, __ENV__)
5469+
# We attach the line: 0 to struct functions because we don't want
5470+
# the generated callbacks to count towards code coverage and metrics,
5471+
# especially since they are often expanded at compile-time.
5472+
functions =
5473+
quote line: 0, unquote: false do
5474+
def __struct__(), do: @__struct__
5475+
def __struct__(unquote(kv)), do: unquote(body)
54655476
end
54665477

5467-
def __struct__(), do: @__struct__
5468-
def __struct__(unquote(kv)), do: unquote(body)
5478+
footer =
5479+
quote do
5480+
Kernel.Utils.announce_struct(__MODULE__)
5481+
struct
5482+
end
54695483

5470-
Kernel.Utils.announce_struct(__MODULE__)
5471-
struct
5472-
end
5484+
{:__block__, [], [header, functions, footer]}
54735485
end
54745486

54755487
@doc ~S"""

0 commit comments

Comments
 (0)