-
Notifications
You must be signed in to change notification settings - Fork 23
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
AST validate that a contract does not have a function with contract name #117
base: main
Are you sure you want to change the base?
AST validate that a contract does not have a function with contract name #117
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
if func_name.as_str() == contract_name { | ||
self.dcx() | ||
.err("functions are not allowed to have the same name as the contract") | ||
.note("if you intend this to be a constructor, use \"constructor(...) { ... }\" to define it") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.note("if you intend this to be a constructor, use \"constructor(...) { ... }\" to define it") | |
.note("if you intend this to be a constructor, use `constructor(...) { ... }` to define it") |
&item.kind | ||
{ | ||
if let Some(func_name) = header.name { | ||
if func_name.as_str() == contract_name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if func_name.as_str() == contract_name { | |
if func_name == contract.name { |
Compare Symbols not strings, it has the same result but faster, which is the point of Symbol in the first place
if let ast::ItemKind::Function(ast::ItemFunction { kind: _, header, body: _ }) = | ||
&item.kind | ||
{ | ||
if let Some(func_name) = header.name { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to also check that kind is Function
This PR adds an AST validation check similar to this which verifies that a function does not have the same name as the contract.
Note, eventually this can be merged into a specific AST contract level checker.