warnings: enable prefer_readonly_array and annotate the 33 flagged sites#3671
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enables the prefer_readonly_array warning in moon.mod and updates documentation examples and tests to explicitly annotate array literal types so the codebase remains warning-clean under the new lint setting.
Changes:
- Enabled
+prefer_readonly_arrayinmoon.mod. - Added explicit
Array[T]/ReadOnlyArray[T]annotations across docs and tests to satisfy the lint. - Updated various README/docstring “mbt check” blocks to keep examples compiling cleanly with the new warning enabled.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| string/README.mbt.md | Annotates a character array example used with String::from_array. |
| set/linked_hash_set_test.mbt | Annotates an input array used to construct a Set. |
| quickcheck/splitmix/README.mbt.md | Annotates generated sequences in deterministic testing examples. |
| moon.mod | Enables the prefer_readonly_array warning. |
| math/algebraic_test.mbt | Annotates an array literal used in a hypot edge-case test. |
| immut/hashset/HAMT_test.mbt | Annotates an input array used with @hashset.from_array. |
| hashset/hashset_test.mbt | Annotates arrays used in HashSet tests (including arbitrary-case fixtures). |
| hashmap/utils_test.mbt | Annotates a key list used to populate a map in a collision-focused test. |
| hashmap/hashmap.mbt | Updates doc examples and test fixtures for HashMap construction/arbitrary testing. |
| hashmap/hashmap_test.mbt | Annotates tuple arrays used for @hashmap.from_array tests. |
| deque/deque.mbt | Annotates a doc example array used to construct a deque. |
| deque/deque_test.mbt | Annotates an array used in deque from_array tests. |
| cmp/README.mbt.md | Annotates an example array of Reverse[Int] values. |
| bytes/README.mbt.md | Annotates a byte array used with Bytes::from_array. |
| builtin/readonlyarray.mbt | Annotates a doc example converting from Array to ReadOnlyArray. |
| builtin/fixedarray.mbt | Annotates a doc example converting from Array to FixedArray. |
| builtin/bytes.mbt | Annotates a doc example byte array used with Bytes::from_array. |
| builtin/arrayview_test.mbt | Annotates an array used to create an ArrayView for suffix tests. |
| builtin/arraycore_nonjs.mbt | Annotates a doc example array literal for Array::new/length. |
| builtin/array.mbt | Annotates doc example arrays for Array methods and operators. |
| builtin/array_test.mbt | Annotates arrays in tests covering append and implicit conversions. |
| builtin/array_sort.mbt | Annotates a doc example array used in sorting-related documentation. |
| buffer/buffer_test.mbt | Annotates a byte array used to build a buffer. |
| bool/README.mbt.md | Uses ReadOnlyArray for read-only indexing examples. |
| bench/README.mbt.md | Uses ReadOnlyArray for a read-only access benchmark example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+149
| let seq1 : Array[Int] = [rng1.next_int(), rng1.next_int(), rng1.next_int()] | ||
| let seq2 : Array[Int] = [rng2.next_int(), rng2.next_int(), rng2.next_int()] |
| ///| | ||
| test "@math.hypot small ratio" { | ||
| let ys = [0.0] | ||
| let ys : Array[Double] = [0.0] |
| // Create keys that likely hash to same buckets | ||
| let map = @hashmap.HashMap([]) | ||
| let keys = ["a", "aa", "aaa", "aaaa", "aaaaa"] | ||
| let keys : Array[String] = ["a", "aa", "aaa", "aaaa", "aaaaa"] |
| test "hashset arbitrary" { | ||
| let samples : Array[@hashset.HashSet[Int]] = @quickcheck.samples(20) | ||
| let cases = [ | ||
| let cases : Array[@hashset.HashSet[Int]] = [ |
| ///| | ||
| test "ArrayView::suffixes" { | ||
| let arr = [1, 2, 3] | ||
| let arr : Array[Int] = [1, 2, 3] |
| test "arbitrary" { | ||
| let samples : Array[HashMap[String, Int]] = @quickcheck.samples(20) | ||
| let data = [ | ||
| let data : Array[Array[(String, Int)]] = [ |
b606145 to
d398bb2
Compare
Collaborator
Coverage Report for CI Build 4643Coverage remained the same at 94.241%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
e7588dd to
fe10350
Compare
…rals Adds `+prefer_readonly_array` to the workspace warn-list and silences the 33 sites the lint flags. Most are docstring / README examples and tests where the Array literal is only read; annotating the binding with an explicit `: Array[T]` (the docs are demonstrating `Array` APIs) or `: ReadOnlyArray[T]` (where the example is purely about indexed read) makes the choice explicit and satisfies the lint. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fe10350 to
ffc92ef
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable
+prefer_readonly_arrayinmoon.modand annotate the 33 sites it flags. Most are docstring/README examples and tests where the Array literal is only read; an explicit: Array[T](when the doc is demonstrating anArrayAPI) or: ReadOnlyArray[T](when the example is purely indexed read) makes the choice explicit and satisfies the lint.Test plan
moon checkclean (0 warnings).moon test— 6521/6521 pass.🤖 Generated with Claude Code