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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I really like this, v nice!</p>
<pre><code>  @type good_hello() :: map() 
  @type bad_hello() :: map() 
  @type any_hello() :: good_hello() | bad_hello()

  @spec hello(integer()) :: any_hello()
  def hello(1), do: good()
  def hello(_), do: bad()

  @spec good() :: good_hello()
  def good(), do: %{hello: "world"}

  @spec bad() :: bad_hello()
  def bad(), do: :wtf
</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="85971" 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/how-to-make-dialyzer-more-strict/13854/42">Post #41</a>
	                </div>
	            </div>
              <div id="likers-container-85971" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="85971"
                     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 #41"></div>
  </section>
</div>
    <div class="postbit" id="156588" data-post-id="156588">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Came across this discussion when searching for Elixir types / dialyzer stuff. I think it’s worth mentioning that with the latest <code>dialyxir</code> (1.0.0-rc7) and Erlang/OTP 22.2, and the <code>overspecs</code> flag that Jose mentioned, dialyzer <em>does</em> catch the error as expected with the example:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">lib/test_types.ex:15: The success typing for 'Elixir.TestTypes':hello/1 implies that the function might also return 'wtf' but the specification return is map()
</code></pre>
<p>Unfortunately, <code>overspecs</code> is noisy and fails, for example this function and spec:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  @spec hi(integer()) :: :foo | :bar
  def hi(n) do
    if n &lt; 5 do
      :foo
    else
      :bar
    end
  end
</code></pre>
<p>with:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Type specification is a subtype of the success typing.

Function:
TestTypes.hi/1

Type specification:
@spec hi(integer()) :: :foo | :bar

Success typing:
@spec hi(_) :: :bar | :foo
</code></pre>
<p>You can fix it by adding <code>def hi(n) when is_integer(n) do</code>.</p>
<p>So it seems like <code>overspecs</code> might be something you could add when you’re starting a project, but hard to enable after the fact.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="156588" data-batch-url="/posts/batch_likers">
                        5
                      </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/how-to-make-dialyzer-more-strict/13854/43">Post #42</a>
	                </div>
	            </div>
              <div id="likers-container-156588" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="156588"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></div>
  </section>
</div>
    <div class="postbit" id="158250" data-post-id="158250">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Question about typespecs:</p>
<blockquote>
<p>The analysis can be improved by inclusion of type hints (called <a href="https://hexdocs.pm/elixir/typespecs.html" rel="noopener nofollow ugc">specs</a>) but it can be useful even without those.</p>
</blockquote>
<p>This is stated in the dialyxir readme (<a href="https://github.com/jeremyjh/dialyxir#with-explaining-stuff" class="inline-onebox" rel="noopener nofollow ugc">GitHub - jeremyjh/dialyxir: Mix tasks to simplify use of Dialyzer in Elixir projects. · GitHub</a>) which implies that adding typespecs makes the analysis better, but when you say</p>
<blockquote>
<p>The compiler always ignores type specs except for some basic syntax checks.</p>
</blockquote>
<p>How can dialyxir/dialyzer be improved through typespecs if they are ignored? Am I not understanding what dialyxir docs mean vs what you mean?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158250" 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/how-to-make-dialyzer-more-strict/13854/44">Post #43</a>
	                </div>
	            </div>
              <div id="likers-container-158250" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158250"
                     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 #43"></div>
  </section>
</div>
    <div class="postbit" id="158251" data-post-id="158251">
  <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">
								<p>The elixir compiler ignores them, except for validating their syntax. (Well it also includes them into the generated byte code).</p>
<p>But dialyzer analysis them, so the more typespecs are there, the more dialyzer knows about the thing its analyzes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158251" 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/how-to-make-dialyzer-more-strict/13854/45">Post #44</a>
	                </div>
	            </div>
              <div id="likers-container-158251" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158251"
                     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 #44"></div>
  </section>
</div>
    <div class="postbit" id="158252" data-post-id="158252">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for the follow up but I’m still not sure which is true. In the paragraph before that <a class="mention" href="/u/rvirding" rel="nofollow">@rvirding</a> says:</p>
<blockquote>
<p>Also in some ways dialyzer basically ignores a function spec when type checking so you don’t really need one to get the type checking. If you give one it will check that it is consistent with what it can work out about the function and it will use it when reporting type errors,</p>
</blockquote>
<p>I’m reading it as “dialyzer ignores elixir typespecs”. <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"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158252" 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/how-to-make-dialyzer-more-strict/13854/46">Post #45</a>
	                </div>
	            </div>
              <div id="likers-container-158252" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158252"
                     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 #45"></div>
  </section>
</div>
    <div class="postbit" id="158255" data-post-id="158255">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As I said it both ignores and doesn’t ignore the erlang/elixir typespecs.</p>
<p>When it does its type checking it will look the code definition of a function and the calls to that function and check if they are consistent. For example if a function expects its first argument to be a list is it will check whether it is called with list. This it does irrespective of whether there is an explicit typespec or not. This means you don’t <strong>need</strong> typespecs to get dialyzer to check your code.</p>
<p>If there is a typespec then it will check the typespec against the function definition to see whether they are consistent and report if they are not. It will also use the typespec when reporting errors.</p>
<p>Try reading the “Learn You Some Erlang” chapter on dialyzer and typing, <a href="https://learnyousomeerlang.com/dialyzer" rel="nofollow">https://learnyousomeerlang.com/dialyzer</a> which explains what is going quite well. While it is in Erlang it should be quite easy to understand. I don’t know of something similar written for Elixir.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158255" data-batch-url="/posts/batch_likers">
                        4
                      </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/how-to-make-dialyzer-more-strict/13854/47">Post #46</a>
	                </div>
	            </div>
              <div id="likers-container-158255" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158255"
                     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 #46"></div>
  </section>
</div>
    <div class="postbit" id="158256" data-post-id="158256">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’ll read it, thank you!</p>
<p>Per your reply, to me it means that typespecs do not help in analysis but rather in reporting (unless I don’t understand what analysis means). I wish I wasn’t so confused.</p>
<blockquote>
<p>The analysis can be improved by inclusion of type hints (called <a href="https://hexdocs.pm/elixir/typespecs.html" rel="noopener nofollow ugc">specs</a>) but it can be useful even without those.</p>
</blockquote>
<p>But yes, will read that chapter.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158256" 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/how-to-make-dialyzer-more-strict/13854/48">Post #47</a>
	                </div>
	            </div>
              <div id="likers-container-158256" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158256"
                     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 #47"></div>
  </section>
</div>
    <div class="postbit" id="158259" data-post-id="158259">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="woohaaha" data-post="48" data-topic="13854">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/48.png" class="avatar"> woohaaha:</div>
<blockquote>
<p>Per your reply, to me it means that typespecs do not help in analysis but rather in reporting (unless I don’t understand what analysis means).</p>
</blockquote>
</aside>
<p>Exactly. Dialyzer will ensure that the typespecs you’ve written down match what it inferred (a.k.a. that they’re not wrong). It helps you to find cases, where your codebase is consistent based on what dialyzer infers, but it’s not consistent with the developers intention.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule A do
  # This is fine
  def calc(a, b), do: a + b
  def run, do: add(1.0, 1.0)
end

# v.s.

defmodule B do
  # This is not
  @spec calc(integer, integer) :: integer
  def calc(a, b), do: a + b
  # The call 'Elixir.B':calc(1.0,float()) breaks the contract (integer(),integer()) -&gt; integer()
  def run, do: add(1.0, 1.0)
end
</code></pre>
<p>Edit: One could’ve added guard clauses with <code>when is_integer(a) and is_integer(b)</code> as well, but I guess for an example it should be fine.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158259" data-batch-url="/posts/batch_likers">
                        3
                      </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/how-to-make-dialyzer-more-strict/13854/49">Post #48</a>
	                </div>
	            </div>
              <div id="likers-container-158259" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158259"
                     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 #48"></div>
  </section>
</div>
    <div class="postbit" id="158266" data-post-id="158266">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="woohaaha" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  woohaaha
                  </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/boom.png?v=15" title=":boom:" class="emoji" alt=":boom:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/exploding_head.png?v=15" title=":exploding_head:" class="emoji" alt=":exploding_head:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/clap.png?v=15" title=":clap:" class="emoji" alt=":clap:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/raised_hands.png?v=15" title=":raised_hands:" class="emoji" alt=":raised_hands:" loading="lazy" width="20" height="20"> <img src="https://forum.elixirforum.com/images/emoji/apple/bowing_man.png?v=15" title=":bowing_man:" class="emoji" alt=":bowing_man:" loading="lazy" width="20" height="20"> thank you!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158266" 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/how-to-make-dialyzer-more-strict/13854/50">Post #49</a>
	                </div>
	            </div>
              <div id="likers-container-158266" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158266"
                     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 #49"></div>
  </section>
</div>
    <div class="postbit" id="158300" data-post-id="158300">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="49" data-topic="13854">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>Edit: One could’ve added guard clauses with <code>when is_integer(a) and is_integer(b)</code> as well, but I guess for an example it should be fine.</p>
</blockquote>
</aside>
<p>This is what I do. Helps keeping me in check.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="158300" 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/how-to-make-dialyzer-more-strict/13854/51">Post #50</a>
	                </div>
	            </div>
              <div id="likers-container-158300" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="158300"
                     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 #50"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/13854/load_more?page=6">Load more posts (1 remaining)</a>
</div></template></turbo-stream>