<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="182709" data-post-id="182709">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lok0613" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lok0613
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">The pattern 
          'false' can never match the type 
          'true'ElixirLS Dialyzer
The test 
          'ok' =:= 
          'true' can never evaluate to 'true'
</code></pre>
<p>Ya you’re right, but you can do this on unit test like <code>assert true</code> and still works fine.<br>
I just simple expression for this sample, in my case I have some complex calculations like <code>apple Compute.diff_value(5, 2) &lt; 7</code>, this depends on the variable in runtime but it still emit warning even I have no idea how dialyzer able to check the return value before I put the parameters..</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="182709" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-182709" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="182709"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="182710" data-post-id="182710">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lok0613" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lok0613
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If my case is</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmacro apple(clause) do
    quote generated: true do
      if unquote(clause) == :ok do
        :ok
      else
        :failure
      end
    end
  end
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">fruits do
    apple :ok
    apple :something_else
  end

  apple :ok
</code></pre>
<p>According to your method, it generate these lines:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">-file("lib/store_front.ex", 1).

-module('Elixir.StoreFront').

-compile([no_auto_import]).

-export(['__info__'/1, run/0, run_fruits/0]).

-spec '__info__'(attributes | compile | functions |
                 macros | md5 | module | deprecated) -&gt; any().

'__info__'(module) -&gt; 'Elixir.StoreFront';
'__info__'(functions) -&gt; [{run, 0}, {run_fruits, 0}];
'__info__'(macros) -&gt; [];
'__info__'(Key = attributes) -&gt;
    erlang:get_module_info('Elixir.StoreFront', Key);
'__info__'(Key = compile) -&gt;
    erlang:get_module_info('Elixir.StoreFront', Key);
'__info__'(Key = md5) -&gt;
    erlang:get_module_info('Elixir.StoreFront', Key);
'__info__'(deprecated) -&gt; [].

run() -&gt;
    'Elixir.IO':inspect(erlang:apply('Elixir.StoreFront',
                                     run_fruits, [])).

run_fruits() -&gt;
    case ok == ok of
      false -&gt; failure;
      true -&gt; ok
    end,
    case something_else == ok of
      false -&gt; failure;
      true -&gt; ok
    end.
:ok
</code></pre>
<p>I could see the root cause right now, however I’m wondering how other libraries e.g. ExUnit didn’t emit the same warning.<br>
Here the problem is no matter things I put next to <code>apple</code> macro under <code>fruits</code>, it emits warning messsages.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="182710" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-182710" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="182710"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="182715" data-post-id="182715">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="lok0613" data-post="12" data-topic="33020">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/l/ac8455/48.png" class="avatar"> lok0613:</div>
<blockquote>
<p>Ya you’re right, but you can do this on unit test like <code>assert true</code> and still works fine.</p>
</blockquote>
</aside>
<p>Dialyzer can only check compiled modules on disk, test files are exs, which don’t get compiled to byte code on disk, but in memory only.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="182715" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-182715" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="182715"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="182717" data-post-id="182717">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lok0613" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lok0613
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><img src="https://forum.elixirforum.com/images/emoji/apple/thinking.png?v=15" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"> I got your point.</p>
<p>Anyway I just tried an alternative way like this and it turns out no warning messages anymore.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">case unquote(clause) do
  x when x in [true, :ok] -&gt; :ok
  _ -&gt; :failure
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="182717" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-182717" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="182717"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="312752" data-post-id="312752">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bobkocisko" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bobkocisko
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Sorry to bump an old topic, but wow, this comment is gold!!  It helped me figure out a mind-bending dialyzer issue related to nesting a <code>case</code> statement inside the <code>else</code> of a <code>with</code>.  Thanks <a class="mention" href="/u/qqwy" rel="nofollow">@Qqwy</a> <img src="https://forum.elixirforum.com/images/emoji/apple/+1.png?v=15" title=":+1:" class="emoji" alt=":+1:" loading="lazy" width="20" height="20">   I am going to keep this in my toolbelt from now to help understand Elixir’s dark corners and edge cases.</p>
<aside class="quote no-group" data-username="Qqwy" data-post="11" data-topic="33020">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qqwy/48/1349_2.png" class="avatar"> Qqwy:</div>
<blockquote>
<p>To check what code you exactly end up with, you might want to use the following incancation by the way:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    f = './_build/dev/lib/your_library_name/ebin/Elixir.YourModuleName.beam'
    result = :beam_lib.chunks(f,[:abstract_code])
    {:ok,{_,[{:abstract_code,{_,ac}}]}} = result
    IO.puts :erl_prettypr.format(:erl_syntax.form_list(ac))
</code></pre>
</blockquote>
</aside> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="312752" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-312752" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="312752"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="352402" data-post-id="352402">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dkerr" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dkerr/120/13347_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dkerr
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I just bumped into this same error unrelated to macros. I am trying to generate a hard-coded uuid in tests so ex_vcr cassettes match on the body reliably. I don’t like production code which serves tests, but this seemed like an acceptable hack to me. I am open to better ways to do this, but this is what I have (env is compiled into the module) and passed into this function.</p>
<p>I have re-written this with matching cases and only ended up on the case trying things from this thread. But the error is the same with an if/else and matching on function inputs.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @env Mix.env()
...
  defp generate_request_id(env) do
    case env do
      :test -&gt; "fake-uuid-for-testing"
      _env -&gt; Ecto.UUID.generate()
    end
  end
</code></pre>
<p>returns</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">::warning file=lib/corex/drivers/video/samsung_display_repo/http_adapter.ex,line=376,title=pattern_match::The pattern can never match the type :dev.
</code></pre>
<p>I don’t get this at all. Of course the environment can be dev, but perhaps it is not in whatever environment dialyzer is running in?</p>
<p>Update:<br>
I ended up just telling dialyzer to ignore that function. I am open to better solutions but this gets me moving at least.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @dialyzer {:nowarn_function, generate_request_id: 1}
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352402" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-352402" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352402"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="352407" data-post-id="352407">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mudasobwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/120/5298_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mudasobwa
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Cure</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="dkerr" data-post="17" data-topic="33020">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dkerr/48/13347_2.png" class="avatar"> dkerr:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @env Mix.env()
  ...
  defp generate_request_id(env) do
    case env do
      :test -&gt; "fake-uuid-for-testing"
      _env -&gt; Ecto.UUID.generate()
    end
  end
</code></pre>
</blockquote>
</aside>
<p>The dialyzer has no clue about elixir macros, it sees the compiled code anyway, meaning it sees somewhat like</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">case :dev do
  :test -&gt; ...
  ...
end
</code></pre>
<p>One should not leak testing abstractions to the code in any case. The proper solution would be to introduce a behaviour and mock it in tests.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule ReqIdGen do
  @callback generate :: binary()
end

defmodule My do
  @behaviour ReqIdGen

  @impl ReqIdGen
  def generate, do: Ecto.UUID.generate()

  @generator Application.compile_env(:my_app, :req_id_gen, __MODULE__)

  defp generate_request_id(generator \\ @generator) do
    generator.generate()
  end
end
</code></pre>
<p>And mock it in tests.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352407" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/weird-dialyzer-warning-the-pattern-can-never-match-the-type/33020/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-352407" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352407"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>