Skip to content

Commit b7a832e

Browse files
authored
Add missing catch-all in :elixir_import.is_sigil/1 (#15264)
Fixes a compiler crash when importing a module with only: :sigils option when the imported module exports non sigil symbols with `sigil_` prefix. Closes #15263.
1 parent 8011552 commit b7a832e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/elixir/src/elixir_import.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ is_sigil({Name, 2}) ->
194194
[H|T] when H >= $A, H =< $Z ->
195195
lists:all(fun(L) -> (L >= $0 andalso L =< $9)
196196
orelse (L>= $A andalso L =< $Z)
197-
end, T)
197+
end, T);
198+
_ -> false
198199
end;
199200
_ ->
200201
false

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ defmodule Kernel.ImportTest do
180180
defmacro bor(x, _), do: x
181181
end
182182

183+
defmodule ModuleWithInvalidSigils do
184+
def sigil_ab(string, []), do: string
185+
def sigil_1(string, []), do: string
186+
def helper(x), do: x
187+
end
188+
183189
test "import only sigils" do
184190
import Kernel, except: [sigil_w: 2]
185191
import ModuleWithSigils, only: :sigils
@@ -204,6 +210,14 @@ defmodule Kernel.ImportTest do
204210
assert ~w(abc def) == ["abc", "def"]
205211
end
206212

213+
test "import only sigils ignores malformed sigil names" do
214+
import ModuleWithInvalidSigils, only: :sigils
215+
216+
assert Macro.Env.lookup_import(__ENV__, {:sigil_ab, 2}) == []
217+
assert Macro.Env.lookup_import(__ENV__, {:sigil_1, 2}) == []
218+
assert Macro.Env.lookup_import(__ENV__, {:helper, 1}) == []
219+
end
220+
207221
test "import only removes the non-import part" do
208222
import List
209223
import List, only: :macros

0 commit comments

Comments
 (0)