Skip to content

Commit f9263fd

Browse files
committed
Do not crash on invalid imports metadata
1 parent 5f2f626 commit f9263fd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/elixir/src/elixir_dispatch.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ find_import_by_name_arity(Tuple, List) ->
329329

330330
is_import(Meta, Arity) ->
331331
case lists:keyfind(imports, 1, Meta) of
332-
{imports, Imports} ->
332+
{imports, [_ | _] = Imports} ->
333333
case lists:keyfind(context, 1, Meta) of
334334
{context, _} ->
335335
case lists:keyfind(Arity, 1, Imports) of
@@ -338,7 +338,7 @@ is_import(Meta, Arity) ->
338338
end;
339339
false -> false
340340
end;
341-
false -> false
341+
_ -> false
342342
end.
343343

344344
% %% We've reached the macro wrapper fun, skip it with the rest

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ defmodule Kernel.ExpansionTest do
446446

447447
assert expand(before_expansion) == after_expansion
448448
end
449+
450+
test "invalid metadata" do
451+
assert expand({:foo, [imports: 2, context: :unknown], [1, 2]}) ==
452+
{:foo, [imports: 2, context: :unknown], [1, 2]}
453+
end
449454
end
450455

451456
describe "floats" do

0 commit comments

Comments
 (0)