Do not try to accidentally load elixir.beam (#739)

This commit is contained in:
José Valim 2021-12-03 22:50:45 +01:00 committed by GitHub
parent 64fce545d3
commit 18d8eccc9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -107,20 +107,23 @@ defmodule Livebook.Intellisense.Docs do
:protocol | :implementation | :exception | :struct | :behaviour | nil
def get_module_subtype(module) do
cond do
module_has_function?(module, :__protocol__, 1) ->
not ensure_loaded?(module) ->
nil
function_exported?(module, :__protocol__, 1) ->
:protocol
module_has_function?(module, :__impl__, 1) ->
function_exported?(module, :__impl__, 1) ->
:implementation
module_has_function?(module, :__struct__, 0) ->
if module_has_function?(module, :exception, 1) do
function_exported?(module, :__struct__, 0) ->
if function_exported?(module, :exception, 1) do
:exception
else
:struct
end
module_has_function?(module, :behaviour_info, 1) ->
function_exported?(module, :behaviour_info, 1) ->
:behaviour
true ->
@ -128,7 +131,9 @@ defmodule Livebook.Intellisense.Docs do
end
end
defp module_has_function?(module, func, arity) do
Code.ensure_loaded?(module) and function_exported?(module, func, arity)
end
# In case insensitive file systems, attempting to load
# Elixir will log a warning in the terminal as it wrongly
# loads elixir.beam, so we explicitly list it.
defp ensure_loaded?(Elixir), do: false
defp ensure_loaded?(module), do: Code.ensure_loaded?(module)
end