-
Notifications
You must be signed in to change notification settings - Fork 66
refactor(parser): move mapping key type validation to semantic analysis #574
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?
refactor(parser): move mapping key type validation to semantic analysis #574
Conversation
mablr
commented
Oct 13, 2025
- Removed the mapping key type validation from the parser and implemented it in the semantic analysis phase.
- Added specific mapping-key-type parsing method and updated accordingly mapping-type parsing method
- Added a new method to check if a type is a valid mapping key type.
- Introduced ui tests to ensure that only elementary or user-defined types can be used as key types in mappings.
- Removed the mapping key type validation from the parser and implemented it in the semantic analysis phase. - Added specific mapping-key-type parsing method and updated accordingly mapping-type parsing method - Added a new method to check if a type is a valid mapping key type. - Introduced ui test to ensure that only elementary or user-defined types can be used as key types in mappings.
- Removed the previous inline validation for mapping key types and centralized it in a dedicated method within the TypeChecker. - Updated the type checking logic to allow only elementary types, user-defined types, contract types, or enums as valid mapping keys. - Updated tests
| mapping(E => uint) m1; | ||
| mapping(U => uint) m2; | ||
| mapping(L.E1 => uint) m3; | ||
| mapping(uint[] => uint) m4; //~ ERROR: expected `=>`, found `[` |
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 PR overall looks good to me, but I'm mulling over this, I understand that this is technically incorrect syntax but part of me wishes this was a more helpful message. no action needed right now as I'm still figuring out if we want it like this or not
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.
I see your point.
This line is actually an edge case because an elementary-type is successfully parsed before falling to parse =>:
mapping(uint[] => uint) m4;but the following:
mapping([] => uint) m4;would return a more insightful error message:
error: expected one of elementary type name or path, found `[`
CodSpeed Performance ReportMerging #574 will degrade performances by 5.3%Comparing Summary
Benchmarks breakdown
|