Skip to content

Commit 2e96d1d

Browse files
author
José Valim
committed
Ensure imports are passed around arg by arg, closes #990
1 parent b5ab795 commit 2e96d1d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,11 +1525,10 @@ defmodule Kernel do
15251525
fields = [{ :__exception__, :__exception__ }|fields]
15261526
record = Record.defrecord(name, fields, opts)
15271527

1528-
check = quote do
1529-
Exception.check! Module.concat(__MODULE__, unquote(name))
1528+
quote do
1529+
unquote(record)
1530+
Exception.check! unquote(name)
15301531
end
1531-
1532-
[record, check]
15331532
end
15341533

15351534
@doc """

lib/elixir/src/elixir_scope.erl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,30 @@ umergev(S1, S2) ->
138138
C1 = S1#elixir_scope.clause_vars,
139139
C2 = S2#elixir_scope.clause_vars,
140140
S2#elixir_scope{
141-
vars=orddict:merge(fun var_merger/3, V1, V2),
141+
vars=merge_vars(V1, V2),
142142
clause_vars=merge_clause_vars(C1, C2)
143143
}.
144144

145-
% Receives two scopes and return a new scope based on the first
146-
% with the counter values from the second one.
145+
% Receives two scopes and return the later scope
146+
% keeping the variables from the first (counters,
147+
% imports and everything else are passed forward).
147148

148149
umergec(S1, S2) ->
149-
S1#elixir_scope{
150-
counter=S2#elixir_scope.counter,
151-
extra_guards=S2#elixir_scope.extra_guards,
152-
super=S1#elixir_scope.super orelse S2#elixir_scope.super,
153-
caller=S1#elixir_scope.caller orelse S2#elixir_scope.caller,
154-
name_args=S1#elixir_scope.name_args orelse S2#elixir_scope.name_args
150+
S2#elixir_scope{
151+
vars=S1#elixir_scope.vars,
152+
temp_vars=S1#elixir_scope.temp_vars,
153+
clause_vars=S1#elixir_scope.clause_vars
155154
}.
156155

157156
% Merge variables trying to find the most recently created.
158157

158+
merge_vars(V, V) -> V;
159+
merge_vars(V1, V2) ->
160+
orddict:merge(fun var_merger/3, V1, V2).
161+
159162
merge_clause_vars(nil, _C2) -> nil;
160163
merge_clause_vars(_C1, nil) -> nil;
164+
merge_clause_vars(C, C) -> C;
161165
merge_clause_vars(C1, C2) ->
162166
orddict:merge(fun var_merger/3, C1, C2).
163167

lib/elixir/test/elixir/kernel/import_test.exs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Kernel.ImportMacrosTest do
111111
end
112112
end
113113

114-
defmodule Kernel.AmbiguousImportTest do
114+
defmodule Kernel.MultipleImportTest do
115115
use ExUnit.Case, async: true
116116

117117
test :import_ambiguous do
@@ -121,4 +121,10 @@ defmodule Kernel.AmbiguousImportTest do
121121
import List
122122
import String
123123
end
124+
125+
test :import_many do
126+
[import(List), import(String)]
127+
assert capitalize("foo") == "Foo"
128+
assert flatten([1,[2],3]) == [1,2,3]
129+
end
124130
end

0 commit comments

Comments
 (0)