Skip to content

Commit aef0879

Browse files
authored
Fix import m, only: :sigils for multi-letter sigils (#12626)
1 parent 926bfe8 commit aef0879

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/elixir/src/elixir_import.erl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,22 @@ import_sigil_macros(Meta, Ref, Opts, E) ->
6565
end
6666
end).
6767

68-
filter_sigils(Key) ->
69-
lists:filter(fun({Atom, _}) ->
70-
case atom_to_list(Atom) of
71-
"sigil_" ++ [L] when L >= $a, L =< $z; L >= $A, L =< $Z -> true;
72-
_ -> false
73-
end
74-
end, Key).
68+
filter_sigils(Funs) ->
69+
lists:filter(fun is_sigil/1, Funs).
70+
71+
is_sigil({Name, 2}) ->
72+
case atom_to_list(Name) of
73+
"sigil_" ++ Letters ->
74+
case Letters of
75+
[L] when L >= $a, L =< $z -> true;
76+
[] -> false;
77+
Letters -> lists:all(fun(L) -> L >= $A andalso L =< $Z end, Letters)
78+
end;
79+
_ ->
80+
false
81+
end;
82+
is_sigil(_) ->
83+
false.
7584

7685
%% Calculates the imports based on only and except
7786

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ defmodule Kernel.ImportTest do
164164
end
165165
end
166166

167+
defmacro sigil_III(string, []) do
168+
quote do
169+
3 * String.to_integer(unquote(string))
170+
end
171+
end
172+
167173
def sigil_w(_string, []), do: []
168174

169175
def bnot(x), do: x
@@ -177,6 +183,7 @@ defmodule Kernel.ImportTest do
177183
# Ensure that both function and macro sigils are imported
178184
assert ~i'10' == 10
179185
assert ~I'10' == 10
186+
assert ~III'10' == 30
180187
assert ~w(abc def) == []
181188

182189
# Ensure that non-sigil functions and macros from ModuleWithSigils were not loaded
@@ -189,6 +196,7 @@ defmodule Kernel.ImportTest do
189196

190197
assert ~i'10' == 10
191198
assert ~I'10' == 10
199+
assert ~III'10' == 30
192200
assert ~w(abc def) == ["abc", "def"]
193201
end
194202

0 commit comments

Comments
 (0)