elixir-lang / elixir

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

Dialyzer errors when using `with` #13947

Open NobbZ opened 3 weeks ago

NobbZ commented 3 weeks ago

Elixir and Erlang/OTP versions

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

Elixir 1.17.0-dev (compiled with Erlang/OTP 27)

I bisected this issue to 0b95ca45c2c81213a9469dff9fa516f3c7b708c1.

Bisection log ```text git bisect start # status: waiting for both good and bad commits # bad: [372836d623fbbeeb6111ed473eb8f64f7bf4b203] Change variable from `bk` to `bucket` (#13921) git bisect bad 372836d623fbbeeb6111ed473eb8f64f7bf4b203 # status: waiting for good commit(s), bad commit known # bad: [fb3db59f7c1274a77dbda8f1438a4daf3975e440] Add use to the title of guide that introduces it (#13559) git bisect bad fb3db59f7c1274a77dbda8f1438a4daf3975e440 # status: waiting for good commit(s), bad commit known # good: [327063cc8485692f2b902553fb599a2bef5a0f8f] Release v1.16.3 git bisect good 327063cc8485692f2b902553fb599a2bef5a0f8f # skip: [bb1f1af1136238f1a378f0939d1a4232ed096ff7] Trim trailing whitespace on heredocs with \r\n git bisect skip bb1f1af1136238f1a378f0939d1a4232ed096ff7 # bad: [ba1de9d6cf5f7c5d6ff46b2ff7aa2886de079e12] Fix typo in docs (#13321) git bisect bad ba1de9d6cf5f7c5d6ff46b2ff7aa2886de079e12 # good: [8f64ca0287da4bc2223c99017c45d34b2c70b5a4] Use Macro.Env in more warnings git bisect good 8f64ca0287da4bc2223c99017c45d34b2c70b5a4 # good: [93605209dc6b7640456b9efacd6aa4ed1e6e932b] Check if inside Mix project folder for recompile (#13261) git bisect good 93605209dc6b7640456b9efacd6aa4ed1e6e932b # good: [3c8a005a03f1feb27b099833f8ee0b9c81ffc438] Default `defimpl` to `@moduledoc false` (#13295) git bisect good 3c8a005a03f1feb27b099833f8ee0b9c81ffc438 # bad: [7ac64110f556edc67af7af61416d4124a4809e24] Fix autocompletion on Erlang/OTP 26, closes #13307 git bisect bad 7ac64110f556edc67af7af61416d4124a4809e24 # bad: [4a11a3362d0c24ce4b9125794b825736d5d8a720] Avoid comparing config mtime in Elixir compiler git bisect bad 4a11a3362d0c24ce4b9125794b825736d5d8a720 # bad: [0b95ca45c2c81213a9469dff9fa516f3c7b708c1] Translate with/1 as a closure (#13299) git bisect bad 0b95ca45c2c81213a9469dff9fa516f3c7b708c1 # good: [92db97eab2228fe86344da91cbfe6f103b529a42] Revert "Fix some broken links in the guides (#13297)" git bisect good 92db97eab2228fe86344da91cbfe6f103b529a42 # good: [5e13403068afd25689d0ff57fa90ca28d2cef66b] Add explicit clarification that values like 0 and "" are truthy in Elixir (#13300) git bisect good 5e13403068afd25689d0ff57fa90ca28d2cef66b # first bad commit: [0b95ca45c2c81213a9469dff9fa516f3c7b708c1] Translate with/1 as a closure (#13299) ```

Operating system

Linux

Current behavior

The code as follows produces a dialyzer error:

  def handle_event("submit", %{"stop" => params}, %{assigns: %{state: state}} = socket) do
    with %State{} = state <- S.with_changes(state, params),
         %{valid?: true} <- S.form_changeset(state),
         :ok <- E.stop(state.some_id, state.another_id, state.yet_another__id, state.reasons, state.details, auth_ctx(socket)) do
      # preparing the live view socket
    else
      %{valid?: false} ->
        # updating live view socket

      error ->
        # logging error and preparing live view socket
    end
  end
lib/file.ex:xxx:pattern_match_cov
The pattern
variable_error

can never match, because previous clauses completely cover the type
%Ecto.Changeset{
  # Chengeset innertias omiited for brevity
}.

E.stop/6 has a type that I can simplify to :ok | {:ok, any()} | {:error, any()} and actual :error returns have been observed in the running code.

Expected behavior

No dialyzer warning as on Elixir 1.16.

josevalim commented 3 weeks ago

Can you please try main? There have been fixes here.

NobbZ commented 3 weeks ago

Sorry, it took a while, as with f2d8064121397d3d628defc762d966fbea71fc42 our project doesn't compile with a weird error. I will bisect that properly later and hopefully create a reproducer.

809971a69065ce1c14c0a63f16caa4085163b0cb built the project and there the reported issue still exists.

josevalim commented 3 weeks ago

Can you report the weird error in main?

NobbZ commented 3 weeks ago

@josevalim Yes, though I have to do some more research and provide a reproducer. I can not hand out or publish the actually failing to build code.

NobbZ commented 3 weeks ago

I reported #13948 and fixed our code to build again.

After that, I can confirm, that f2d8064121397d3d628defc762d966fbea71fc42 has the same dialyzer error.

sabiwara commented 2 weeks ago

@NobbZ Thank you for confirming, unfortunately I couldn't manage to reproduce it on my end. Could you please provide the specs and types of all functions being passed? (or ideally, provide a self-contained repro with simpler functions/types, if possible).

NobbZ commented 2 weeks ago

The code is in a business repo. And I can't share it in fully.

Also I can't allot much more time during working hours for this issue.

I still will see if I can create a reproducer during the next weekend. Sorry for the resulting delay.