-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Allow named parameters in mapping types #13384
Conversation
@@ -10,4 +10,6 @@ contract Error2 { | |||
mapping (address => uint balances; // missing ) before "balances" | |||
} | |||
// ---- | |||
// ParserError 6635: (417-425): Expected ')' but got identifier | |||
// ParserError 6635: (425-426): Expected ')' but got ';' |
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.
Some existing error recovery tests change their behavior because a syntax that was illegal before (i.e. ability to place an identifier next to type in mapping) is legal now, hence the parser passes further and generates a different error.
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.
Looks quite good! Some small comments.
We were wondering with the annotations, if it makes sense to have the function call options syntax for mappings. For example, for mapping (address user => uint balance) balanceOf
, would the syntax balanceOf[{user: 0xaddress}]
be allowed? It's not needed to implement it in this PR, but worth thinking about.
Also, it's missing a changelog entry.
Can you add a semantic test as well? https://github.com/ethereum/solidity/blob/develop/test/libsolidity/semanticTests/getters/mapping.sol here is an example |
Could you also add an example in the documentation? |
Thanks for the review! I've made the changes.
This might be tricky for nested mappings: |
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.
already looking very good.
Additionally to the comments, I am wondering if it makes sense to make it an optional<ASTPointer<ASTString>>
.
Would love to hear @cameel and @christianparpart on that topic
Depends if we prefer to treat it as a missing name or an empty name. That will show up in the AST. But overall Also, I can't see any place in the AST where we'd have a single optional name but in a few cases we do have vectors of names and that's closer to |
I have rebased over the latest Edit: I'm not able to request reviews from multiple people. cc: @hrkrshnn, @Marenz, @cameel, @nishant-sachdeva. (Sorry for tagging). |
Will rebase now |
test/libsolidity/syntaxTests/parsing/mapping_with_names_conflict_3.sol
Outdated
Show resolved
Hide resolved
test/libsolidity/syntaxTests/parsing/mapping_with_names_struct_member_4.sol
Show resolved
Hide resolved
50bdbeb
to
7142217
Compare
I've pushed an empty commit, squash and pushed in the hopes of restarting the build successfully, but unfortunately we seem to have CI problems, which will hopefully be resolved soon. In fact, as soon as that happens, I'll restart the build to see whether everything passes, and then I'll resume reviewing. |
825f3de
to
67057e6
Compare
test/libsolidity/syntaxTests/parsing/mapping_with_names_struct_member_6.sol
Show resolved
Hide resolved
02024df
to
cf24f9d
Compare
Co-authored-by: Hari <[email protected]> test: add parser and abi test cases docs: add example on using named parameters for mappings - Add changelog feat: update antlr grammar to allow named parameters in mappings fix: prevent conflicting mapping parameter names ref: change order of mapping initializers test: update expectations and fix build test: add more tests fix: use common error & code for conflicting params fix: issue with accessing nested mapping test: add conflicting params tests for more nested levels Update libsolidity/analysis/DeclarationTypeChecker.cpp Co-authored-by: Nikola Matić <[email protected]> fix: error reported with the same code twice test: add more tests for 3 level nested mapping Address review comments
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.
Closes #11407
Please let me know of any changes that are needed.