Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/typed_struct.ex
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ defmodule TypedStruct do
unquote(name),
unquote(tag)
)

# Clean up accumulating attributes after each record definition
Enum.each(unquote(@record_accumulating_attrs), fn attr ->
Module.delete_attribute(__MODULE__, attr)
end)
end
end

Expand Down
19 changes: 19 additions & 0 deletions test/typed_record_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,23 @@ defmodule TypedRecordTest do
end
end
end

defmodule MultipleRecords do
use TypedStruct

typedrecord :first do
field :a, integer(), default: 42
end

typedrecord :second do
field :b, String.t(), default: "hello"
end
end

test "multiple typedrecords in the same module" do
import MultipleRecords, only: [first: 0, second: 0]

assert first() == {:first, 42}
assert second() == {:second, "hello"}
end
end