Skip to content

Commit 636da42

Browse files
author
Jonathan J Hunt
committed
Don't ignore nil during aliasing. Attempt to fix #1159
1 parent 7e856e1 commit 636da42

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* bug fix
88
* [IEx] Do not interpret ANSI codes in IEx results
99
* [Mix] Fix usage of shell expressions in `Mix.Shell.cmd`
10+
* [Kernel] Don't ignore :nil when dispatching protocols to avoid infinite loops.
1011

1112
* deprecations
1213

lib/elixir/src/elixir_aliases.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ raw_concat(['Elixir'|Args]) -> do_concat(Args);
137137
raw_concat(Args) -> do_concat(Args).
138138

139139
do_concat(Args) ->
140-
Aliases = [to_partial(Arg) || Arg <- Args, Arg /= nil],
140+
Aliases = [to_partial(Arg) || Arg <- Args],
141141
"Elixir" ++ lists:concat(Aliases).
142142

143143
to_partial(Arg) when is_binary(Arg) -> to_partial(binary_to_list(Arg));

lib/elixir/test/elixir/module_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ defmodule ModuleTest do
161161
assert Module.concat(Foo, 'Bar') == Foo.Bar
162162
assert Module.concat(Foo, Bar.Baz) == Foo.Bar.Baz
163163
assert Module.concat(Foo, "Bar.Baz") == Foo.Bar.Baz
164+
assert Module.concat(Bar, :nil) == :"Elixir.Bar.nil"
164165
end
165166

166167
test :safe_concat do

lib/elixir/test/elixir/protocol_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ defmodule ProtocolTest do
104104
false = ProtocolTest.WithAll.blank(ProtocolTest.Foo.new(a: 1))
105105
end
106106

107+
test :protocol_with_nil_record do
108+
assert_raise UndefinedFunctionError, fn ->
109+
ProtocolTest.WithOnly.blank({:nil})
110+
end
111+
end
112+
107113
test :protocol_for do
108114
assert_protocol_for(ProtocolTest.WithAll, Atom, :foo)
109115
assert_protocol_for(ProtocolTest.WithAll, Function, fn(x) -> x end)

0 commit comments

Comments
 (0)