Fix parsing crash when return is ternary conditional product

logical-or-coverage
cgewecke 5 years ago
parent 57ce8cbeb6
commit 0763bd6ee9
  1. 2
      lib/instrumenter.js
  2. 9
      lib/parse.js
  3. 11
      test/sources/solidity/contracts/return/ternary-return.sol
  4. 7
      test/units/expressions.js

@ -61,8 +61,6 @@ class Instrumenter {
// First, we run over the original contract to get the source mapping. // First, we run over the original contract to get the source mapping.
let ast = SolidityParser.parse(contract.source, {range: true}); let ast = SolidityParser.parse(contract.source, {range: true});
//console.log(JSON.stringify(ast, null, ' '))
parse[ast.type](contract, ast); parse[ast.type](contract, ast);
const retValue = JSON.parse(JSON.stringify(contract)); // Possibly apotropaic. const retValue = JSON.parse(JSON.stringify(contract)); // Possibly apotropaic.

@ -70,10 +70,13 @@ parse.FunctionCall = function(contract, expression, skipStatementRegistry) {
} }
}; };
parse.Conditional = function(contract, expression) { parse.Conditional = function(contract, expression, skipStatementRegistry) {
if (!skipStatementRegistry){
register.statement(contract, expression); register.statement(contract, expression);
// TODO: Investigate node structure }
// There are potential substatements here we aren't measuring
parse[expression.condition.type] &&
parse[expression.condition.type](contract, expression.condition, skipStatementRegistry);
}; };
parse.ContractDefinition = function(contract, expression) { parse.ContractDefinition = function(contract, expression) {

@ -0,0 +1,11 @@
pragma solidity ^0.5.0;
contract Test {
function a(uint x) public pure returns (uint) {
return x > 3 ? x : 1;
}
function b(uint x) public pure returns (uint) {
return (x > 3) ? x : 1;
}
}

@ -17,8 +17,13 @@ describe('generic expressions / misc', () => {
util.report(info.solcOutput.errors); util.report(info.solcOutput.errors);
}); });
it('should compile after instrumenting function the returns void', () => { it('should compile after instrumenting function that returns void', () => {
const info = util.instrumentAndCompile('return/empty-return'); const info = util.instrumentAndCompile('return/empty-return');
util.report(info.solcOutput.errors); util.report(info.solcOutput.errors);
}); });
it('should compile after instrumenting function that returns via ternary conditional', () => {
const info = util.instrumentAndCompile('return/ternary-return');
util.report(info.solcOutput.errors);
});
}); });

Loading…
Cancel
Save