Fix bug preprocessing unbracketed if else statements

pull/344/head
cgewecke 5 years ago
parent a2e0eab7bc
commit b4f1e5c20a
  1. 3
      lib/preprocessor.js
  2. 8
      test/if.js
  3. 10
      test/sources/if/if-else-no-brackets.sol

@ -57,7 +57,8 @@ module.exports.run = function r(contract) {
if (node.trueBody.type !== 'Block') {
insertions.push({type: OPEN, pos: node.trueBody.range[0]});
insertions.push({type: CLOSE, pos: node.trueBody.range[1] + 1});
} else if ( node.falseBody && node.falseBody.type !== 'Block' ) {
}
if ( node.falseBody && node.falseBody.type !== 'Block' ) {
insertions.push({type: OPEN, pos: node.falseBody.range[0]});
insertions.push({type: CLOSE, pos: node.falseBody.range[1] + 1});
}

@ -19,6 +19,14 @@ describe('if, else, and else if statements', () => {
util.report(output.errors);
});
it('should compile after instrumenting unbracketed if-elses', () => {
const contract = util.getCode('if/if-else-no-brackets.sol');
const info = getInstrumentedVersion(contract, filePath);
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
util.report(output.errors);
});
it('should cover an if statement with a bracketed consequent', done => {
const contract = util.getCode('if/if-with-brackets.sol');
const info = getInstrumentedVersion(contract, filePath);

@ -0,0 +1,10 @@
pragma solidity ^0.5.0;
contract Test {
function a(uint x,uint y, uint z) public {
if (x==y)
x = 5;
else
x = 7;
}
}
Loading…
Cancel
Save