Skip to content

Type checker crashes (MatchError in Of.refine_body_var/5) when a for generator uses a variable bound in into: or reduce: #16102

Closed

Description

@alpaylan

Existing issue

  • I have searched existing issues and could not find a duplicate.

Elixir and Erlang/OTP versions

Erlang/OTP 28 [erts-16.4.0.7] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.21.0-dev (3a11ef4) (compiled with Erlang/OTP 28) # main
Elixir 1.20.5 (compiled with Erlang/OTP 28)

Operating system

Ubuntu 24.04.5 LTS (Linux 7.0.0, x86_64)

Current behavior

Snippet (repro.exs)

defmodule A do
  def f(list), do: for(x <- items, into: (items = list; []), do: x)
end

IO.inspect(A.f([1, 2]), label: "A.f([1, 2])")

Result

$ elixir repro.exs
# main and v1.20.5:
** (RuntimeError) found error while checking types for A.f/1:

** (MatchError) no match of right hand side value:

    %{
      vars: %{
        0 => %{name: :list, ...}
      },
      ...
    }

The exception happened while checking this code:

def f(list) do
  for x <- items,
      do: x,
      into:
        (
          items = list
          []
        )
end

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

    (elixir 1.21.0-dev) lib/module/types/of.ex:114: Module.Types.Of.refine_body_var/5
    (elixir 1.21.0-dev) lib/module/types/helpers.ex:583: Module.Types.Helpers.zip_map_reduce/5
    (elixir 1.21.0-dev) lib/module/types/apply.ex:410: Module.Types.Apply.remote/8
    (elixir 1.21.0-dev) lib/module/types/expr.ex:879: Module.Types.Expr.for_clause/3
    (elixir 1.21.0-dev) lib/enum.ex:2643: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir 1.21.0-dev) lib/module/types/expr.ex:676: anonymous fn/6 in Module.Types.Expr.of_expr/5

Expected behavior

The module compiles and runs:

$ elixir repro.exs
# expected: A.f([1, 2]): [1, 2]
# main:     ** (RuntimeError) found error while checking types for A.f/1: ** (MatchError) ...

Activity

  1. alpaylan commented on Nov 11, 2026

    @alpaylan
    Author

    Hi @josevalim @gldubc,

    This report and #16101 come from an agentic property-based testing framework I am working on called Ephyra, I have 7 more local reports, I can send file them if this style of report and the amount of information provided is useful for you. Please let me know how I should continue forward.

  2. josevalim commented on Nov 11, 2026

    @josevalim
    Member

    @alpaylan if you have 7 other, you can open up issues. That amount is manageable. And thank you for asking first, that's very kind.

  3. alpaylan commented on Nov 11, 2026

    @alpaylan
    Author

    Thank you very much @josevalim, I filed the remaining 7. Please let me know if I can be helpful in any way.

  4. josevalim commented on Nov 11, 2026

    @josevalim
    Member

    Btw, @alpaylan, could you write one paragraph or two (it is ok to ask AI to dump a summary of the session) about how you used Ephyra to find these bugs? My initial reaction was that it was a Rust project, so I am curious about how it found Elixir bugs! Thank you once again!

  5. alpaylan commented on Nov 11, 2026

    @alpaylan
    Author

    @josevalim will do! I can also share the harness if you would be interested in using it! It's definitionally slop, because I treat the generator code as an "observational artifact", so the generator is essentially judged not by its code but by its measurable metrics. I am working on a UX that makes it possible to hide the monstrous synthesized generator completely, but that'll take some time to nail I think.

  6. josevalim commented on Nov 11, 2026

    @josevalim
    Member

    Slop is fine, it is not meant to be a committed artifact anyway! And I agree the bugs it finds is what really matters! Anything you can share will be definitely useful!

  7. alpaylan commented on Nov 11, 2026

    @alpaylan
    Author

    @josevalim
    You can view it here #16113

  8. added a commit that references this issue on Nov 12, 2026
    d1f2079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions