Skip to content

fix FixedArray::get and corresponding doc test #2146

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

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

Conversation

myfreess
Copy link
Contributor

No description provided.

Copy link

peter-jerry-ye-code-review bot commented May 22, 2025

Example tests in documentation don't match the updated function signature

Category
Correctness
Code Snippet
test "FixedArray::get" {
let arr : FixedArray[Int] = [1, 2, 3]
inspect!(arr.get(1), content="Some(2)")
}
Recommendation
Update example to explicitly handle the optional return type:

test "FixedArray::get" {
  let arr : FixedArray[Int] = [1, 2, 3]
  match arr.get(1) {
    Some(value) => inspect!(value, content="2")
    None => fail!("unexpected None")
  }
}```
**Reasoning**
The current example might be misleading as it doesn't demonstrate proper pattern matching on optional values, which is important for the new API

</details>
<details>

<summary> Guard condition could be more readable with a single boundary check </summary>

**Category**
Maintainability
**Code Snippet**
guard idx >= 0 && idx < len else { None }
**Recommendation**
Consider introducing a helper function:
```moonbit
fn is_valid_index(idx: Int, len: Int) -> Bool {
  idx >= 0 && idx < len
}

// Then use:
guard is_valid_index(idx, len) else { None }```
**Reasoning**
A named helper function would make the intent clearer and could be reused in other array operations that need bounds checking

</details>
<details>

<summary> Consider adding test case for negative indices </summary>

**Category**
Correctness
**Code Snippet**
test "FixedArray::get/out_of_bounds" {
  let arr : FixedArray[Int] = [1, 2, 3]
  inspect!(arr.get(3), content="None")
}
**Recommendation**
Add test case for negative indices:
```moonbit
test "FixedArray::get/negative_index" {
  let arr : FixedArray[Int] = [1, 2, 3]
  inspect!(arr.get(-1), content="None")
}```
**Reasoning**
The current test suite only verifies upper bound checking. Testing negative indices would ensure complete bounds checking behavior

</details>

@coveralls
Copy link
Collaborator

coveralls commented May 22, 2025

Pull Request Test Coverage Report for Build 6878

Details

  • 0 of 3 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 92.421%

Changes Missing Coverage Covered Lines Changed/Added Lines %
builtin/fixedarray.mbt 0 3 0.0%
Totals Coverage Status
Change from base Build 6872: -0.03%
Covered Lines: 8695
Relevant Lines: 9408

💛 - Coveralls

@myfreess myfreess requested a review from peter-jerry-ye May 22, 2025 03:50
Copy link
Collaborator

@peter-jerry-ye peter-jerry-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires migration phase

@peter-jerry-ye peter-jerry-ye marked this pull request as draft May 22, 2025 06:56
@myfreess myfreess force-pushed the myfreess/fix-fixedarray-get branch from 5f03de8 to e280753 Compare May 23, 2025 02:48
@myfreess myfreess force-pushed the myfreess/fix-fixedarray-get branch from e280753 to ca6a7ad Compare May 23, 2025 02:50
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.

3 participants