Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/elixir/lib/module/types/of.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ defmodule Module.Types.Of do
# so we need to deal with such cases accordingly.
# TODO: Assume implementation is available on Elixir v2.0.
# A warning is emitted since v1.19+.
if info = mode == :closed && Code.ensure_loaded?(struct) && struct.__info__(:struct) do
info =
mode == :closed and Code.ensure_loaded?(struct) and
function_exported?(struct, :__info__, 1) and struct.__info__(:struct)

if info do
struct_type(struct, info)
else
open_map(__struct__: {atom([struct]), false})
Expand Down
25 changes: 25 additions & 0 deletions lib/elixir/test/elixir/module/types/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ defmodule Module.Types.IntegrationTest do
dynamic(open_map(__struct__: {atom([Unknown]), false}))
end

test "writes exports for implementations of Erlang modules" do
files = %{
"pe.ex" => """
defprotocol Erl do
def erl(data)
end

defimpl Erl, for: :gen_server do
def erl(data), do: data
end
"""
}

modules = compile_modules(files)

{_, %{sig: {:infer, nil, [{[domain], _return}]}}} =
List.keyfind(
read_chunk(modules[Module.concat(Erl, :gen_server)]).exports,
{:erl, 1},
0
)

assert domain == open_map(__struct__: {atom([:gen_server]), false})
end

test "ignores additional callbacks on implementations" do
files = %{
"p.ex" => """
Expand Down