From 57ce8cbeb600551d43af244e2d913fa9052eedd0 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 20 Apr 2020 16:50:56 -0700 Subject: [PATCH] Fix parsing crash when return is void --- lib/parse.js | 1 + test/sources/solidity/contracts/return/empty-return.sol | 7 +++++++ test/units/expressions.js | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 test/sources/solidity/contracts/return/empty-return.sol diff --git a/lib/parse.js b/lib/parse.js index 4765637..ca053be 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -190,6 +190,7 @@ parse.SourceUnit = function(contract, expression) { parse.ReturnStatement = function(contract, expression) { register.statement(contract, expression); + expression.expression && parse[expression.expression.type] && parse[expression.expression.type](contract, expression.expression, true); }; diff --git a/test/sources/solidity/contracts/return/empty-return.sol b/test/sources/solidity/contracts/return/empty-return.sol new file mode 100644 index 0000000..1d7d541 --- /dev/null +++ b/test/sources/solidity/contracts/return/empty-return.sol @@ -0,0 +1,7 @@ +pragma solidity ^0.5.0; + +contract Test { + function a(uint x) public pure { + return; + } +} diff --git a/test/units/expressions.js b/test/units/expressions.js index b007c29..8c71880 100644 --- a/test/units/expressions.js +++ b/test/units/expressions.js @@ -16,4 +16,9 @@ describe('generic expressions / misc', () => { const info = util.instrumentAndCompile('return/return'); util.report(info.solcOutput.errors); }); + + it('should compile after instrumenting function the returns void', () => { + const info = util.instrumentAndCompile('return/empty-return'); + util.report(info.solcOutput.errors); + }); });