solidity-parser / parser

A Solidity parser for JS built on top of a robust ANTLR4 grammar
MIT License
157 stars 44 forks source link

Unable to detect unnamed overriding #41

Closed lonelyenvoy closed 3 years ago

lonelyenvoy commented 3 years ago

I want to find out function overriding and function modifier overriding in the AST. However, it seems not possible in some situation.

contract A {
  function f(uint a) public virtual {
    return a + 1;
  }
}

contract B is A {
  function f(uint a) public override { // cannot detect
    return a + 2;
  }
}

The override array of the FunctionDefinition node of B.f is empty, which means I cannot know whether a function is overriding another function in the parent contract. However, the code below works:

contract A {
  function f(uint a) public virtual {
    return a + 1;
  }
}

contract B is A {
  function f(uint a) public override(A) { // can detect
    return a + 2;
  }
}

When the name is explicitly given in override(...), the override array contains one element. How can I detect unnamed overriding? The same situation happens on function modifier overriding:

contract A {
  modifier m() virtual { _; }
}

contract B is A {
  modifier m() override { _; } // cannot detect
}
fvictorio commented 3 years ago

Yes, sorry about that, this project has 0 docs at the moment.

When a function node doesn't have an override modifier, the value of the override property for that node is null.

If it does have an override but it doesn't passes any contract name, then the override property is [].

Finally, if there are explicit overrides, the override property has a list of the UserDefinedTypeName nodes that are used.

Does that help?

lonelyenvoy commented 3 years ago

Oh, I understand. Thanks for your explanation.