sc-forks / solidity-coverage

Code coverage for Solidity smart-contracts
MIT License
978 stars 264 forks source link

Non-ascii chars cause compilation failure, (inserting `else` branch in the wrong place) #418

Open boolafish opened 5 years ago

boolafish commented 5 years ago

What

Somehow the coverage tool inserts the else in wrong place and make the contract non-compilable. (It failed to insert after the { of if block and inserted inside the if)

Error: CompileError: /home/circleci/repo/plasma_framework/.coverage_contracts/src/transactions/eip712Libs/PaymentEip712Lib.sol:138:8: ParserError: Expected primary expression.
       else { coverage_0x2e142684(0x95339fce433c333b185bc690238a8492dbe8aa4afb211e28c4d5a379ce051e16); /* branch */ 

Here is one error instance on our CI: https://circleci.com/gh/omisego/plasma-contracts/3663 I make a branch for the failing code: https://github.com/boolafish/plasma-contracts/tree/solidity_coverage_bug_inserting_coverage_op_wrongly

I think the root cause is I copy pasted some weird symbol to the code comment and it start to fail. And I tried to fix with this commit: https://github.com/omisego/plasma-contracts/pull/325/commits/c7ff3eb8d469ab010b39c121a5b218275d44e86f

It was able to work locally (to compile)

Version

cgewecke commented 5 years ago

Thanks so much @boolafish.

For future reference, we need to replace to non-ascii characters in the source files as part of pre-processing because they mess up the parser range counts somehow.

str.replace(/[^\x00-\x7F]/g, " ");