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

'Unchecked' Not Properly Recognized #36

Open
Philogy opened this issue Nov 12, 2022 · 7 comments
Open

'Unchecked' Not Properly Recognized #36

Philogy opened this issue Nov 12, 2022 · 7 comments

Comments

@Philogy
Copy link
Contributor

Philogy commented Nov 12, 2022

Unsure what's incorrect with the grammar, probably something to do with the "optional" unchecked on L485 but the first few lines in the block are not recognized properly and neither are the blocks after.

Don't really know how to test / debug this but wanted to note it here, thx.

@JoranHonig
Copy link
Owner

Do you have an example that's parsed incorrectly?

bonus points if you have it in the test case format:

https://github.com/JoranHonig/tree-sitter-solidity/blob/master/test/corpus/constructor.txt

(whoof only seeing now that this response is a bit late 😅 )

@Philogy
Copy link
Contributor Author

Philogy commented Feb 21, 2023

Don't really have that much experience with tree-sitter, are there any good resources you could point to that could help me debug this locally? Is syntax highlighting working for you around / within unchecked blocks?

@JoranHonig
Copy link
Owner

What are you using for syntax highlighting?

I'm not sure if nvim uses the latest version of this parser.

@Philogy
Copy link
Contributor Author

Philogy commented Feb 21, 2023

I use nvim-treesitter with the config option ensure_installed. Running :TSUpdate tells me that "all parsers are up-to-date!"

@Wilfred
Copy link

Wilfred commented Apr 12, 2023

I can reproduce this:

function absOZ(int256 n) pure returns (uint256) {
    unchecked {
        return uint256(0);
    }
}

Produces:

source_file (0, 0) - (6, 0)
  function_definition (0, 0) - (4, 1)
    function (0, 0) - (0, 8) "function"
    identifier (0, 9) - (0, 14) "absOZ"
    ( (0, 14) - (0, 15) "("
    parameter (0, 15) - (0, 23)
      type_name (0, 15) - (0, 21)
        primitive_type (0, 15) - (0, 21)
          int256 (0, 15) - (0, 21) "int256"
      identifier (0, 22) - (0, 23) "n"
    ) (0, 23) - (0, 24) ")"
    state_mutability (0, 25) - (0, 29)
      pure (0, 25) - (0, 29) "pure"
    return_type_definition (0, 30) - (0, 47)
      returns (0, 30) - (0, 37) "returns"
      ( (0, 38) - (0, 39) "("
      parameter (0, 39) - (0, 46)
        type_name (0, 39) - (0, 46)
          primitive_type (0, 39) - (0, 46)
            uint256 (0, 39) - (0, 46) "uint256"
      ) (0, 46) - (0, 47) ")"
    function_body (0, 48) - (4, 1)
      { (0, 48) - (0, 49) "{"
      block_statement (1, 4) - (3, 5)
        { (1, 14) - (1, 15) "{"
        return_statement (2, 8) - (2, 26)
          return (2, 8) - (2, 14) "return"
          type_cast_expression (2, 15) - (2, 25)
            primitive_type (2, 15) - (2, 22)
              uint256 (2, 15) - (2, 22) "uint256"
            ( (2, 22) - (2, 23) "("
            number_literal (2, 23) - (2, 24) "0"
            ) (2, 24) - (2, 25) ")"
        } (3, 4) - (3, 5) "}"
      } (4, 0) - (4, 1) "}"

Note that neither unchecked nor the semicolons are included here, which limits what I can do in difftastic.

@vquelque
Copy link

I guess we could fix this by either transforming the "unchecked" rule to a non-hidden rule or by creating 2 different rules to capture "unchecked" and "normal" block statements and wrapping those rules in an anonymous rule.
Not sure what's the best solution.

   _unchecked: $ => "unchecked",
   unchecked_block_statement: $ => seq($._unchecked, '{', repeat($._statement), "}"),
   block_statement: $ => seq('{', repeat($._statement), "}"),
   //anonymous rule to either match unchecked or normal block statement
   _block_statement: $ => choice($.block_statement, $.unchecked_block_statement),

@JoranHonig
Copy link
Owner

slow response 😅

fixed the parser end of things:
#55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants