From 350e6997626da190b6fbb275db51d971d9db308a Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 4 Jan 2021 21:22:51 -0800 Subject: [PATCH] Do not treat inheritance constructors as branches (#594) --- lib/registrar.js | 2 +- .../contracts/modifiers/constructor.sol | 17 +++++++++++++++++ test/units/modifiers.js | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/sources/solidity/contracts/modifiers/constructor.sol diff --git a/lib/registrar.js b/lib/registrar.js index 328f25b..389a84e 100644 --- a/lib/registrar.js +++ b/lib/registrar.js @@ -129,7 +129,7 @@ class Registrar { } // Add modifier branch coverage - if (!this.enabled.modifiers) continue; + if (!this.enabled.modifiers || expression.isConstructor) continue; this.addNewModifierBranch(contract, modifier); this._createInjectionPoint( diff --git a/test/sources/solidity/contracts/modifiers/constructor.sol b/test/sources/solidity/contracts/modifiers/constructor.sol new file mode 100644 index 0000000..d28b3f7 --- /dev/null +++ b/test/sources/solidity/contracts/modifiers/constructor.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.7.0; + +contract Parent { + string public name; + + constructor(string memory _name) public { + name = _name; + } +} + +contract Test is Parent { + constructor() public Parent("Test") {} + + function a() public { + uint x = 5; + } +} diff --git a/test/units/modifiers.js b/test/units/modifiers.js index 0b2bf1b..4af3a2b 100644 --- a/test/units/modifiers.js +++ b/test/units/modifiers.js @@ -160,4 +160,10 @@ describe('modifiers', () => { 1: 1, 2: 1, 3: 1 }); }); + + it('should *not* treat constructor inheritance invocations as branches', async function() { + const mapping = await setupAndRun('modifiers/constructor'); + assert.deepEqual(mapping[util.filePath].b, {}); + }); + });