Bug 19163 – static/tuple foreach counted incorrectly in coverage analysis

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-08-13T07:52:21Z
Last change time
2018-11-25T10:25:37Z
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2018-08-13T07:52:21Z
import std.meta : AliasSeq; unittest { foreach (n; 0..7) sw: switch (n) { static foreach (i, e; AliasSeq!(int, string, bool)) case i: break sw; foreach (i, e; AliasSeq!(int, string, bool)) case i+3: break sw; default: break; } static foreach (i, e; AliasSeq!(int, string, bool)) { } foreach (i, e; AliasSeq!(int, string, bool)) { } } The above code gives this coverage analysis: |import std.meta : AliasSeq; | |unittest { 24| foreach (n; 0..7) 7| sw: switch (n) { 0000000| static foreach (i, e; AliasSeq!(int, string, bool)) 3| case i: 3| break sw; 0000000| foreach (i, e; AliasSeq!(int, string, bool)) 3| case i+3: 3| break sw; 1| default: 1| break; | } 6| static foreach (i, e; AliasSeq!(int, string, bool)) { | } 6| foreach (i, e; AliasSeq!(int, string, bool)) { | } |} Four things stand out here - the static foreach and tuple foreach inside the switch has a coverage count of 0, and the foreach outside are counted. I contend that both are incorrect - the lines contain no run-time executable code, and so shouldn't show up in the coverage report at all.
Comment #1 by default_357-line — 2018-11-23T13:52:32Z
Just ran into this as well. Quite annoying.
Comment #2 by github-bugzilla — 2018-11-25T10:25:37Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/a92014451e3c244cf77ed4d07f9294eb309d83f6 Fix issue 19163: don't count codeless expressions in coverage analysis https://github.com/dlang/dmd/commit/1e5d5816ca9f1c8c35f2d339615f8edffa660442 issue 19163: add testcase https://github.com/dlang/dmd/commit/6307b3aa9f4f5c45baad9f0d7d13ed89b098d285 Merge pull request #8997 from FeepingCreature/fix/issue-19163-decls-counted-in-coverage-analysis Fix issue 19163: don't count declarations in coverage analysis