From 1565ec7a962b2c30569f5bfef3923ede408d9b3a Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 25 Jan 2024 13:37:01 -0800 Subject: [PATCH] Inject ternary conditionals before branches --- lib/instrumenter.js | 4 +++- .../conditional/ternary-with-unbracketed-else.sol | 8 ++++++++ test/units/conditional.js | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/sources/solidity/contracts/conditional/ternary-with-unbracketed-else.sol diff --git a/lib/instrumenter.js b/lib/instrumenter.js index 988f90ea..68bcfe09 100644 --- a/lib/instrumenter.js +++ b/lib/instrumenter.js @@ -96,8 +96,10 @@ class Instrumenter { // Line instrumentation has to happen first contract.injectionPoints[injectionPoint].sort((a, b) => { const injections = [ - 'injectLogicalOR', 'injectBranch', + 'injectOpenParen', + 'injectOrFalse', + 'injectAndTrue', 'injectEmptyBranch', 'injectLine' ]; diff --git a/test/sources/solidity/contracts/conditional/ternary-with-unbracketed-else.sol b/test/sources/solidity/contracts/conditional/ternary-with-unbracketed-else.sol new file mode 100644 index 00000000..36802f98 --- /dev/null +++ b/test/sources/solidity/contracts/conditional/ternary-with-unbracketed-else.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.7.0; + +contract Test { + function a() public { + int i = 0; + if (false) {} else i == 0 ? i = 0 : i--; + } +} diff --git a/test/units/conditional.js b/test/units/conditional.js index d8fcd815..84185e5c 100644 --- a/test/units/conditional.js +++ b/test/units/conditional.js @@ -229,4 +229,8 @@ describe('ternary conditionals', () => { }); }); + it('should compile after instrumenting a ternary conditional which follows an unbracketed else', () => { + const info = util.instrumentAndCompile('conditional/ternary-with-unbracketed-else'); + util.report(info.solcOutput.errors); + }); });