Skip to content

Conversation

@mablr
Copy link
Contributor

@mablr 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.

mablr added 4 commits October 13, 2025 12:02
- 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
@mablr mablr marked this pull request as ready for review October 13, 2025 19:58
mapping(E => uint) m1;
mapping(U => uint) m2;
mapping(L.E1 => uint) m3;
mapping(uint[] => uint) m4; //~ ERROR: expected `=>`, found `[`
Copy link
Contributor

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

Copy link
Contributor Author

@mablr mablr Oct 15, 2025

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-hq
Copy link

codspeed-hq bot commented Oct 15, 2025

CodSpeed Performance Report

Merging #574 will degrade performances by 5.3%

Comparing mablr:chore/move_mapping_key_type_to_type_checker (3eb63f1) with main (d79239c)

Summary

❌ 1 regression
✅ 34 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
Solarray/parse 2.7 ms 2.8 ms -5.3%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants