-
Notifications
You must be signed in to change notification settings - Fork 253
Fix: Match Solidity behavior for memory array deletion (issue #1785) #1795
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
base: main
Are you sure you want to change the base?
Fix: Match Solidity behavior for memory array deletion (issue #1785) #1795
Conversation
…dger-solang#1785) Signed-off-by: Pratyksh <[email protected]>
f2d4df4 to
4de1994
Compare
seanyoung
left a comment
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.
Thank you for your contribution. The main problem is that output from sema should be the same as the source tree, i.e. you can't replace a delete statement with something else. Many components, e.g. solang language server, depend on the AST being accurate.
src/sema/statements.rs
Outdated
| // Issue #1785 - match Solc behavior for delete array[index] | ||
| ns.diagnostics.push(Diagnostic::warning( | ||
| *loc, | ||
| "argument to 'delete' should be storage reference".to_string(), |
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.
Here are you still generating a warning. Should be removed for array elements.
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.
No warnings are generated for memory array delete operations
src/sema/statements.rs
Outdated
| right: Box::new(default_expr), | ||
| }; | ||
|
|
||
| res.push(Statement::Expression(*loc, true, assign)); |
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.
The problem here is that the AST should be an accurate representation of the source code, not of the code it will generate - that happens in codegen.
So in sema, add:
res.push(Statement::Delete(...);Then in codegen, for array elements, set a default value, here:
https://github.com/hyperledger-solang/solang/blob/main/src/codegen/statements/mod.rs#L217
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.
handled array elements in codegen
src/sema/statements.rs
Outdated
| } | ||
|
|
||
| /// Helper function to get the default value expression for a type | ||
| fn get_default_value( |
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 already have a function for default values in codegen. Let me know if you need some help locating 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.
Removed the redundant function
Signed-off-by: Pratyksh Gupta <[email protected]>
|
Please look into this @seanyoung |
Description
This PR fixes behavior of
deleteoperator when used with memory arrays to match Solidity's behavior. Previously, the delete operator was not correctly handling memory array elements, which could lead to unexpected behavior.Related Issue
Closes #1785