Skip to content
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

Legacy TupleExpression processor is unable to unnest single tuple element #52

Open
blitz-1306 opened this issue Jul 20, 2021 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@blitz-1306
Copy link
Contributor

blitz-1306 commented Jul 20, 2021

Environment

Any

Scenario

  1. Create a Solidity source file sample.sol with following contents:
contract Test {
    function some(uint a, uint b) pure public returns(uint, uint) {
        return ((a, b));
    }

    function verify() public {
        (uint a, uint b) = some(1, 2);

        assert(a == 1);
        assert(b == 2);
    }
}
  1. Run following command:
sol-ast-compile sample.sol --tree --compiler-version 0.4.26

Expected behavior

Expected to get short AST tree description.

Current behavior

Got following error:

Error: Expected component of type uint256 but got component of type tuple(uint256,uint256)
    at LegacyTupleExpressionProcessor.extractComponentsFromTypeString (solc-typed-ast/dist/ast/legacy/tuple_expression_processor.js:49:27)
    at LegacyTupleExpressionProcessor.process (solc-typed-ast/dist/ast/legacy/tuple_expression_processor.js:14:20)
    at ASTReader.convert (solc-typed-ast/dist/ast/ast_reader.js:159:32)
    at ASTReader.convertArray (solc-typed-ast/dist/ast/ast_reader.js:174:35)
    at LegacyReturnProcessor.process (solc-typed-ast/dist/ast/legacy/return_processor.js:8:48)
    at ASTReader.convert (solc-typed-ast/dist/ast/ast_reader.js:159:32)
    at ASTReader.convertArray (solc-typed-ast/dist/ast/ast_reader.js:174:35)
    at LegacyBlockProcessor.process (solc-typed-ast/dist/ast/legacy/block_processor.js:8:35)
    at ASTReader.convert (solc-typed-ast/dist/ast/ast_reader.js:159:32)
    at ASTReader.convertArray (solc-typed-ast/dist/ast/ast_reader.js:174:35)

Description

Legacy TupleExpression processor is fragile: it not supports tuple unnesting. When we have a single member in tuple, like ((1)), Solidity unnest it by default to 1. Same applies to nested tuple expressions, like in example above.

Regards.

@blitz-1306 blitz-1306 added the bug Something isn't working label Jul 20, 2021
@blitz-1306 blitz-1306 added the good first issue Good for newcomers label Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant