Skip to content

refactor(map): align op_get with array #2305

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peter-jerry-ye
Copy link
Collaborator

Closes #1332

Copy link

peter-jerry-ye-code-review bot commented Jun 20, 2025

HashMap op_get implementation may have incorrect probe sequence length check

Category
Correctness
Code Snippet
guard i <= entry.psl // in hashmap/linked_hash_map.mbt
Recommendation
Change to guard entry.psl >= i to match hashmap.mbt implementation
Reasoning
The probe sequence length (PSL) check seems reversed compared to the implementation in hashmap.mbt which uses guard entry.psl >= i. Having inconsistent PSL checks could lead to incorrect probing behavior.

Missing documentation for Map::op_get panic behavior

Category
Maintainability
Code Snippet
fn[K : Hash + Eq, V] Map::op_get(Self[K, V], K) -> V // in builtin.mbti
Recommendation
Add documentation comment explaining that op_get panics when key doesn't exist
Reasoning
The breaking change from optional to non-optional return type needs to be clearly documented since it introduces panic behavior. This helps prevent runtime errors from misuse.

Test case pattern `guard m is { ... }` could be more exhaustive

Category
Maintainability
Code Snippet
guard m is { "a": 1, "b": 2, "c": 3, "d"? : None, .. }
Recommendation
Add more cases testing different combinations of existing/non-existing keys
Reasoning
The new pattern matching syntax for maps is a significant feature but current tests only verify basic cases. More comprehensive tests would help ensure correctness of the implementation.

@coveralls
Copy link
Collaborator

coveralls commented Jun 20, 2025

Pull Request Test Coverage Report for Build 7424

Details

  • 24 of 26 (92.31%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.006%) to 90.102%

Changes Missing Coverage Covered Lines Changed/Added Lines %
builtin/linked_hash_map.mbt 4 5 80.0%
hashmap/hashmap.mbt 4 5 80.0%
Totals Coverage Status
Change from base Build 7423: 0.006%
Covered Lines: 8548
Relevant Lines: 9487

💛 - Coveralls

@bobzhang bobzhang force-pushed the zihang/align_op_get branch from 39252ae to 51687d3 Compare June 22, 2025 07:59
@bobzhang
Copy link
Contributor

I suggest we hold on this for 2 weeks to have AI updating most existing libs

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.

Align op_get of map and array
3 participants