Skip to content

Fix typechecker crash on non elixir struct module in defimpl - #15891

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-defimpl-crash
Sep 13, 2026
Merged

Fix typechecker crash on non elixir struct module in defimpl#15891
josevalim merged 1 commit into
elixir-lang:mainfrom
lukaszsamson:ls-defimpl-crash

Conversation

@lukaszsamson

Copy link
Copy Markdown
Contributor

Ensure the module exports info/1
Mimic check from struct_info/6

This PR fixes typechecker crash on the following code:

    defprotocol OxP do
      def f(x)
    end

    defimpl OxP, for: :gen_server do
      def f(x), do: x
    end
    == Compilation error in file repro.exs ==
    ** (UndefinedFunctionError) function :gen_server.__info__/1 is undefined or private
        (stdlib 7.3) :gen_server.__info__(:struct)
        (elixir 1.21.0-dev) lib/module/types/of.ex:294: Module.Types.Of.impl/2
        (elixir 1.21.0-dev) lib/module/types.ex:154: Module.Types.default_domain/4
        (elixir 1.21.0-dev) lib/module/types.ex:297: Module.Types.local_handler/5

The code is invalid but it should not crash the typechecker. We can think if defimpl could error on compilation

AssistedBy: test created with Claude Opus 5

Ensure the module exports __info__/1
Mimic check from struct_info/6
@josevalim
josevalim merged commit d35e294 into elixir-lang:main Sep 13, 2026
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants