Skip to content

Commit 08e9faa

Browse files
author
José Valim
committed
Fix a bug with nested record definitions
1 parent e5f9dbd commit 08e9faa

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* bug fix
66
* [Dict] `Enum.to_list` and `Dict.to_list` now return the same results for dicts
7+
* [Record] Fix a bug where nested records cannot be defined
78
* [Mix] Fix a bug where `mix deps.get` was not retrieving nested dependencies
89

910
* deprecations

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ defmodule Kernel.SpecialForms do
424424
module name. This means that the variable is associated to the
425425
ContextSample module and only code generated by this module
426426
will be able to access that particular `world` variable.
427+
While this means macros from the same module could have
428+
conflicting variables, it also allows different quotes from
429+
the same module to access them.
427430
428431
The context can be disabled or changed by explicitly setting
429432
the context option. All hygiene mechanisms are based on such

lib/elixir/lib/record.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Record do
2626
block = Keyword.get(opts, :do, nil)
2727

2828
quote do
29-
values = unquote(values)
29+
unquoted_values = unquote(values)
3030

3131
defmodule unquote(name) do
3232
@moduledoc false
@@ -35,6 +35,10 @@ defmodule Record do
3535
@record_fields []
3636
@record_types []
3737

38+
# Reassign values to inner scope to
39+
# avoid conflicts in nested records
40+
values = unquoted_values
41+
3842
Record.deffunctions(values, __ENV__)
3943
value = unquote(block)
4044
Record.deftypes(values, @record_types, __ENV__)

lib/elixir/test/elixir/record_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ defmodule RecordTest.Macros do
5656
def nested_record_alias?(Nested[]) do
5757
true
5858
end
59+
60+
defrecord NestedInNested, it_compiles: true
5961
end
6062

6163
def new() do

0 commit comments

Comments
 (0)