elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.51k stars 3.38k forks source link

Protocol.UndefinedError executing tests on elixir 1.17.2 #13770

Closed ischepin closed 3 months ago

ischepin commented 3 months ago

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Elixir 1.17.2 (compiled with Erlang/OTP 27)

Operating system

Darwin xxx 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64

Current behavior

RuntimeError running tests:

In the output there is also the test code itself, but I'd prefer not to share it since its from a private repo.

** (EXIT from #PID<0.94.0>) an exception was raised:
    ** (RuntimeError) found error while checking types for XXX."test process/1 uses manager email when email is missing"/1:

** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Floki.HTMLTree, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream, Table.Mapper, Table.Zipper, Timex.Interval
The exception happened while checking this code:

...

expr =
        {:assert, [line: 76],
         [
           {:=, [line: 76],
            [
              :ok,
              {{:., [line: 76], [{:__aliases__, [line: 76], [:CreateUser]}, :process]},
               [line: 76],
               [
                 {:%, [line: 76],
                  [
                    {:__aliases__, [line: 76], [:Oban, :Job]},
                    {:%{}, [line: 76],
                     args:
                       {:%, [line: 76],
                        [
                          {:__aliases__, [line: 76], [:CreateUser]},
                          {:%{}, [line: 76],
                           user_id:
                             {{:., [line: 76], [{:cx_aff, [line: 76], nil}, :user_id]},
                              [no_parens: true, line: 76], []}}
                        ]}}
                  ]}
               ]}
            ]}
         ]}

      [] =
        case right do
          :ok ->
            case right do
              x when :erlang.orelse(:erlang."=:="(x, false), :erlang."=:="(x, nil)) ->
                :erlang.error(
                  ExUnit.AssertionError.exception(
                    expr: expr,
                    message: <<"Expected truthy, got ", Kernel.inspect(right)::binary>>
                  )
                )

              _ ->
                :ok
            end

            []

          _ ->
            left = :ok

            :erlang.error(
              ExUnit.AssertionError.exception(
                left: left,
                right: right,
                expr: expr,
                message: <<"match (=) failed", ExUnit.Assertions.__pins__([])::binary>>,
                context: {:match, []}
              )
            )
        end

      right

      Please report this bug at: https://github.com/elixir-lang/elixir/issues

        (elixir 1.17.2) lib/enum.ex:1: Enumerable.impl_for!/1
        (elixir 1.17.2) lib/enum.ex:166: Enumerable.reduce/3
        (elixir 1.17.2) lib/enum.ex:4423: Enum.reduce/3
        (elixir 1.17.2) lib/module/types/of.ex:182: Module.Types.Of.struct/6
        (elixir 1.17.2) lib/module/types/of.ex:162: anonymous fn/4 in Module.Types.Of.struct/7
        (elixir 1.17.2) lib/module/types/helpers.ex:128: Module.Types.Helpers.do_map_reduce_ok/3
        (elixir 1.17.2) lib/module/types/of.ex:161: Module.Types.Of.struct/7
        (elixir 1.17.2) lib/module/types/helpers.ex:128: Module.Types.Helpers.do_map_reduce_ok/3
        (elixir 1.17.2) lib/module/types/expr.ex:332: Module.Types.Expr.of_expr/3
        (elixir 1.17.2) lib/module/types/expr.ex:125: Module.Types.Expr.of_expr/3
        (elixir 1.17.2) lib/module/types/helpers.ex:128: Module.Types.Helpers.do_map_reduce_ok/3
        (elixir 1.17.2) lib/module/types/expr.ex:185: Module.Types.Expr.of_expr/3
        (elixir 1.17.2) lib/module/types/expr.ex:503: anonymous fn/3 in Module.Types.Expr.of_clauses/3
        (elixir 1.17.2) lib/module/types/helpers.ex:108: Module.Types.Helpers.do_reduce_ok/3
        (elixir 1.17.2) lib/module/types/expr.ex:219: Module.Types.Expr.of_expr/3
        (elixir 1.17.2) lib/module/types/helpers.ex:128: Module.Types.Helpers.do_map_reduce_ok/3
        (elixir 1.17.2) lib/module/types/expr.ex:332: Module.Types.Expr.of_expr/3
        (elixir 1.17.2) lib/module/types/helpers.ex:128: Module.Types.Helpers.do_map_reduce_ok/3
        (elixir 1.17.2) lib/module/types/expr.ex:185: Module.Types.Expr.of_expr/3
        (elixir 1.17.2) lib/module/types.ex:56: Module.Types.warnings_from_clause/6

Expected behavior

Test is executed without errors

josevalim commented 3 months ago

Thank you for the report. I understand you cannot share the whole repo, but we need a small reproduction to make sure we fix it. Can you try isolating the particular modules and files that can make this happen?

ischepin commented 3 months ago

After some investigation I think this is caused by Mimic module. The setup is like this: CreateUser is a Oban.Worker module

Somehow if I run tests for A and B simultaneously it causes the error mentioned above. In any case, bumping mimic 1.7.4->1.9.0 fixes the issue

josevalim commented 3 months ago

Perfect, that's indeed a Mimic issue then. I remember it being discussed previously. :)

sabiwara commented 3 months ago

I remember it being discussed previously. :)

The issue in question for reference: https://github.com/elixir-lang/elixir/issues/13662 https://github.com/edgurgel/mimic/issues/65