You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a variable is defined as part of a return statement and then returns uninitialized, foundry coverage misses this. I found this issue when improving test coverage for this method in ERC1271.sol. It was trivial to recreate this issue in a stripped down experiment:
Contract
contractCoverage {
function notCovered() publicpurereturns (uint256a, bytes32b, bytes[] memoryc) {
a =1;
b = b;
c = c;
}
function covered() publicpurereturns (uint256a, bytes32b, bytes[] memoryc) {
a =1;
b =bytes32(0);
c =newbytes[](0);
}
}
Test
contractCoverageTestisTest {
Coverage public coverage;
function setUp() public {
coverage =newCoverage();
}
function test_notCovered() public {
(uint256a, bytes32b, bytes[] memoryc) = coverage.notCovered();
assertEq(a, 1);
assertEq(b, bytes32(0));
assertEq(c, newbytes[](0));
}
function test_covered() public {
(uint256a, bytes32b, bytes[] memoryc) = coverage.covered();
assertEq(a, 1);
assertEq(b, bytes32(0));
assertEq(c, newbytes[](0));
}
}
Coverage report
Uncovered for src/Coverage.sol:
- Line (location: source ID 25, line 8, chars 198-203, hits: 0)
- Statement (location: source ID 25, line 8, chars 198-203, hits: 0)
- Line (location: source ID 25, line 9, chars 213-218, hits: 0)
- Statement (location: source ID 25, line 9, chars 213-218, hits: 0)
where lines 8 and 9 refer to b = b; and c = c; in method notCovered().
The text was updated successfully, but these errors were encountered:
zerosnacks
changed the title
Coverage report misses return-declared variables if returned as-is
bug: coverage report misses return-declared variables if returned as-is
Jul 12, 2024
A PR was made for this edge case, however per comment here #8442 (comment) there are other ways to replicate same behavior. Fixing all these scenarios will introduce code complexity that we'd rather avoid. More, having coverage reporting such lines should contribute to keeping code clean. We ack the limitation and close this as won't fix, please reopen if you think it's something critical and should be addressed. Thank you!
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (545cd0b 2024-03-14T00:20:00.210934000Z)
What command(s) is the bug in?
forge coverage
Operating System
macOS (Apple Silicon)
Describe the bug
If a variable is defined as part of a return statement and then returns uninitialized, foundry coverage misses this. I found this issue when improving test coverage for this method in ERC1271.sol. It was trivial to recreate this issue in a stripped down experiment:
Contract
Test
Coverage report
where lines 8 and 9 refer to
b = b;
andc = c;
in methodnotCovered()
.The text was updated successfully, but these errors were encountered: