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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="semmitmondo" data-post="11" data-topic="38571">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/semmitmondo/48/3864_2.png" class="avatar"> semmitmondo:</div>
<blockquote>
<p>In this case lines from 2 to 5 are not coverable (not green, nor red, just plain white).</p>
</blockquote>
</aside>
<p>Does this behavior persist if the lines contain something more complicated than a literal?</p>
<p>IIRC there’s a gotcha with coverage related to lines with a bare literal. Some related discussion: <a href="https://forum.elixirforum.com/t/save-my-from-myself-code-coverage-misses-lines-that-return-a-literal/24931" class="inline-onebox" rel="nofollow">Save my from myself: Code coverage misses lines that return a literal</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="246375" 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/surprising-lines-missing-from-coverage-results/38571/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-246375" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="246375"
                     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="246393" data-post-id="246393">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Of course, not.  This only happens when the AST representation of the line is not the usual 3-tuple with the metadata in the middle of it.  (That means, if the representation is the term itself, like numbers, atoms, lists, 2-tuples, strings, maybe others.)  The problem is that it is totally realistic that one writes a single atom, or a tuple like <code>{:error, :not_found}</code> into a clause body.  This thing should work even with very simple literals.  <code>try</code> works, so I believe it is possible to fix <code>with</code> too.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="246393" 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/surprising-lines-missing-from-coverage-results/38571/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-246393" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="246393"
                     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="246396" data-post-id="246396">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The fix is based on <code>-&gt;</code>, so it can’t work on if/unless. <code>with</code> has issues because we mark some clauses as generated to make Dialyzer happy but this will be fixed when we depend on Erlang/OTP 25. Perhaps we can do conditional compilation to have the benefits sooner.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="246396" 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/surprising-lines-missing-from-coverage-results/38571/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-246396" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="246396"
                     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="308018" data-post-id="308018">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi,</p>
<p>unfortunately this problem still exists.  I totally understand the root cause of the issue (that is the missing line information in the quoted expressions), but found out that the <code>else</code> branch of a <code>with</code> special form actually has the line info in it, but coverage tools are not using it.  Here is an oversimplified example (I use integers in it for two reasons: 1) ensure that no accidental line info is added, 2) make it easier to compare the Elixir code with the AST):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">66       with 1 &lt;- 2,
67           3 &lt;- 4 do
68         5
69       else
70         6 -&gt;
71           7
72
73         {8, 9, 10, 11, 12} -&gt;
74           13
75
76        14 -&gt;  
77           15 + 0
78   
79         _ -&gt;
80           42
81       end
</code></pre>
<p>Here’s how it look like when code coverage is checked:</p>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/3/a/3a0a74eda034b438782f1c6d548257e31007ea82.png" data-download-href="https://forum.elixirforum.com/uploads/default/3a0a74eda034b438782f1c6d548257e31007ea82" title="Screenshot from 2023-11-15 10-29-56" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/3X/3/a/3a0a74eda034b438782f1c6d548257e31007ea82.png" alt="Screenshot from 2023-11-15 10-29-56" data-base62-sha1="8hs5ZZlZyroeUZDBOjcm80lP7fc" width="370" height="326"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2023-11-15 10-29-56</span><span class="informations">370×326 11.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>The <code>&lt;-</code> lines are perfect.  I understand why <code>5</code> (line 68) is not involved, that’s OK.  But the <code>else</code> section looks strange. Only <code>15 + 0</code> is covered because of the <code>+</code> function call, not even the 5-tuple before the arrow.</p>
<p>Here’s the relevant part of the AST:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    else: [
      {:-&gt;, [line: 71, column: 9], [[6], 7]},
      {:-&gt;, [line: 74, column: 26],
       [[{:{}, [line: 74, column: 7], [8, 9, 10, 11, 12]}], 13]},
      {:-&gt;, [line: 77, column: 10],
       [[14], {:+, [line: 78, column: 12], [15, 0]}]},
      {:-&gt;, [line: 80, column: 9], [[{:_, [line: 80, column: 7], nil}], 42]}
    ]
</code></pre>
<ul>
<li>As you can see all <code>:-&gt;</code> 3-tuples have proper line metadata, but not used in coverage for some reason.</li>
<li>The ast of <code>{8, 9, 10, 11, 12}</code> has line metadata on the left hand side of the arrow, still not used in coverage.</li>
<li>Only when the right hand side of the arrow contains line metadata, then is the line used in coverage reports.</li>
</ul>
<p>Is it possible to fix this somehow?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="308018" 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/surprising-lines-missing-from-coverage-results/38571/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-308018" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="308018"
                     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="308120" data-post-id="308120">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As mentioned earlier:</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="14" data-topic="38571">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p><code>with</code> has issues because we mark some clauses as generated to make Dialyzer happy but this will be fixed when we depend on Erlang/OTP 25.</p>
</blockquote>
</aside>
<p>There is no option besides making <code>with</code> raise false warnings for those using Dialyzer <img src="https://forum.elixirforum.com/images/emoji/apple/frowning.png?v=15" title=":frowning:" class="emoji" alt=":frowning:" loading="lazy" width="20" height="20"> I thought we would be able to use Erlang’s maybe, but guard support is missing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="308120" 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/surprising-lines-missing-from-coverage-results/38571/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-308120" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="308120"
                     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>