Skip to content

Multiline ternary chains don't instrument correctly #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chapati23 opened this issue Feb 8, 2018 · 3 comments
Closed

Multiline ternary chains don't instrument correctly #192

chapati23 opened this issue Feb 8, 2018 · 3 comments
Labels

Comments

@chapati23
Copy link

Description

Both truffle compile (using global truffle) as well as yarn truffle compile (using local truffle) work. However, the second truffle compile that's running inside solidity-coverage throws an error during compilation and I don't understand how this could happen because it seems I'm using the same version everywhere. Is it an issue with the instrumentation?

Versions

macOS 10.13.3
node.js 9.4.0
truffle (global) 4.0.1 with solidity 0.4.18
truffle (local) 4.0.1 with solidity 0.4.18

The Error

This error occurs during the second compilation, if I understand solidity-coverage correctly, this means after instrumentation

smart-contracts/coverageEnv/contracts/Cov.sol:27:9: TypeError: Wrong argument count for function call: 2 arguments given but expected 1.
      : balances[_address]
        ^
Spanning multiple lines.

smart-contracts/coverageEnv/contracts/Cov.sol:25:81: TypeError: True expression's type tuple(tuple(),uint8) doesn't match false expression's type uint256.
uint256 _totalPerTokenUnclaimedConverted; (,_totalPerTokenUnclaimedConverted) = totalPerTokenPayout == 0
                                                                                ^

pasted_image_08_02_18__12_59

How To Reproduce

Here's a minimum contract to reproduce:

pragma solidity 0.4.18;

import "zeppelin-solidity/contracts/token/PausableToken.sol";

contract TestToken is PausableToken {
  uint256 public totalPerTokenPayout;
  mapping(address => uint256) public claimedPerTokenPayouts;

  function TestToken () public { }

  function currentPayout(address _address)
    public
    view
    returns (uint256)
  {
    uint256 _totalPerTokenUnclaimedConverted = totalPerTokenPayout == 0
      ? 0
      : balances[_address]
      .mul(totalPerTokenPayout.sub(claimedPerTokenPayouts[_address]))
      .div(1e18);

    return _totalPerTokenUnclaimedConverted;
  }
}
@cgewecke
Copy link
Member

cgewecke commented Feb 8, 2018

@chapati23 This is very likely an instrumentation bug. We try to capture branch data for ternary operators and you are using a relatively complex multiline / chained expression. If you have a chance, could you see if the error is resolved by restructuring the code in your example as a conventional if/else statement?

@cgewecke cgewecke added the bug label Feb 8, 2018
@chapati23
Copy link
Author

Indeed. If I get rid of the ternary, the TypeError disappears.

@cgewecke cgewecke changed the title TypeError when running solidity-coverage. Doesn't occur when running truffle compile directly Multiline ternary chains don't instrument correctly Feb 9, 2018
@cgewecke
Copy link
Member

cgewecke commented Feb 3, 2024

Fixed for the nth time in #830

@cgewecke cgewecke closed this as completed Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants