# Codecov missing coverage of myfunction(::SomeType) = 1

**URL:** <https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796>\
**Category:** Tooling\
**Tags:** coverage, codecov\
**Created:** [November 18, 2024, 10:58pm UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796 "2024-11-18T22:58:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffFessler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jefffessler/32/6650_2.png) [@JeffFessler](https://discourse.julialang.org/u/JeffFessler)\
**Post date:** [November 18, 2024, 10:58pm UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796/1 "2024-11-18T22:58:39Z")

</div>

I have some packages that previously had 100% code coverage but now the badges are showing \<100% coverage because codecov is falsely claiming that some lines that look like  
`myfunction(::SomeType) = 1`  
are not being covered, when in fact I am sure they are covered.  
I have a hunch that the compiler is optimizing these functions away and codecov does not realize that. Is there any way to make the codecov report more accurate?

Here is a concrete example report (but I don’t know if such reports are publicly viewable):

> **[Code coverage done right.](https://app.codecov.io/github/JuliaImageRecon/ImagePhantoms.jl/blob/main/src%2Fdirac2.jl)**
>
> Hosted coverage report highly integrated with GitHub, Bitbucket and GitLab. Awesome pull request comments to enhance your QA.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [November 19, 2024, 2:20pm UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796/2 "2024-11-19T14:20:44Z")

</div>

Known issue, see, for example:

> <https://github.com/JuliaLang/julia/issues/54214>
>
> In an otherwise empty directory, I have \`j.jl\`:
> 
> \`\`\`julia
> f( ::Tuple{}) = 1
> …f(t::Tuple{Int}) = only(t)
> 
> f(())
> f((3,))
> \`\`\`
> 
> When I run \`julia --code-coverage=@ j.jl\`, I get:
> 
> \`\`\`none
> - f( ::Tuple{}) = 1
> 1 f(t::Tuple{Int}) = only(t)
> - 
> - f(())
> - f((3,))
> \`\`\`
> 
> So the empty tuple method doesn't seem to get any code coverage recorded.
> 
> \`\`\`julia-repl
> julia\> versioninfo()
> Julia Version 1.12.0-DEV.387
> Commit b5bfd83a3d0 (2024-04-22 13:12 UTC)
> Build Info:
> Official https://julialang.org/ release
> Platform Info:
> OS: Linux (x86\_64-linux-gnu)
> CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
> WORD\_SIZE: 64
> LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
> Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
> Environment:
> JULIA\_NUM\_PRECOMPILE\_TASKS = 3
> JULIA\_PKG\_PRECOMPILE\_AUTO = 0
> \`\`\`
> 
> Hitting this here: https://github.com/JuliaArrays/FixedSizeArrays.jl/pull/26

---

<div class="post-metadata">

**Author:** ![JeffFessler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jefffessler/32/6650_2.png) [@JeffFessler](https://discourse.julialang.org/u/JeffFessler)\
**Post date:** [November 19, 2024, 3:17pm UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796/3 "2024-11-19T15:17:50Z")

</div>

Thanks! I had searched discourse for info and couldn’t find anything, figuring it was a codecov bug. I didn’t realize it was an issue with Julia itself.  
And indeed my examples are always cases where the function returns an isbits literal.  
What is not mentioned in that Julia issue is that these things used to be covered properly not that long ago, so some change in 1.10 or 1.11 or so caused the problem.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [November 20, 2024, 11:49am UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796/4 "2024-11-20T11:49:03Z")

</div>

> [@JeffFessler](#):
>
> What is not mentioned in that Julia issue is that these things used to be covered properly not that long ago, so some change in 1.10 or 1.11 or so caused the problem.

I think this is a long-standing issue for Julia. It’s probably just that the bug didn’t trigger for your code before, perhaps because Julia wasn’t able to constant-fold the relevant pieces of code previously.

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [December 8, 2024, 10:03pm UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796/5 "2024-12-08T22:03:04Z")

</div>

So apparently you can now ignore such problematic code with [this directive](https://github.com/JuliaCI/Coverage.jl?tab=readme-ov-file#exclude-specific-lines-or-sections-from-coverage):

> To exclude specific code blocks, surround the section with `COV_EXCL_START` and `COV_EXCL_STOP` comments:
> 
> ```julia
> # COV_EXCL_START
> foo() = nothing
> # COV_EXCL_STOP
> 
> ```
> 
> To exclude a single line, add a comment with `COV_EXCL_LINE`:
> 
> ```julia
> const a = 1 # COV_EXCL_LINE
> 
> ```

---

<div class="post-metadata">

**Author:** ![JeffFessler](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jefffessler/32/6650_2.png) [@JeffFessler](https://discourse.julialang.org/u/JeffFessler)\
**Post date:** [December 9, 2024, 1:59am UTC](https://discourse.julialang.org/t/codecov-missing-coverage-of-myfunction-sometype-1/122796/6 "2024-12-09T01:59:18Z")

</div>

Thanks - that’s a helpful workaround until the Julia issue gets fixed.
