Skip to content

warnings: enable prefer_readonly_array and annotate the 33 flagged sites#3671

Merged
bobzhang merged 1 commit into
mainfrom
hongbo/warn-prefer-readonly-array
Jun 7, 2026
Merged

warnings: enable prefer_readonly_array and annotate the 33 flagged sites#3671
bobzhang merged 1 commit into
mainfrom
hongbo/warn-prefer-readonly-array

Conversation

@bobzhang
Copy link
Copy Markdown
Contributor

@bobzhang bobzhang commented Jun 7, 2026

Summary

Enable +prefer_readonly_array in moon.mod and 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 an Array API) or : ReadOnlyArray[T] (when the example is purely indexed read) makes the choice explicit and satisfies the lint.

Test plan

  • moon check clean (0 warnings).
  • moon test — 6521/6521 pass.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 7, 2026 00:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_array in moon.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 thread quickcheck/splitmix/README.mbt.md Outdated
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()]
Comment thread math/algebraic_test.mbt Outdated
///|
test "@math.hypot small ratio" {
let ys = [0.0]
let ys : Array[Double] = [0.0]
Comment thread hashmap/utils_test.mbt Outdated
// 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"]
Comment thread hashset/hashset_test.mbt Outdated
test "hashset arbitrary" {
let samples : Array[@hashset.HashSet[Int]] = @quickcheck.samples(20)
let cases = [
let cases : Array[@hashset.HashSet[Int]] = [
Comment thread builtin/arrayview_test.mbt Outdated
///|
test "ArrayView::suffixes" {
let arr = [1, 2, 3]
let arr : Array[Int] = [1, 2, 3]
Comment thread hashmap/hashmap.mbt Outdated
test "arbitrary" {
let samples : Array[HashMap[String, Int]] = @quickcheck.samples(20)
let data = [
let data : Array[Array[(String, Int)]] = [
@bobzhang bobzhang force-pushed the hongbo/warn-prefer-readonly-array branch 2 times, most recently from b606145 to d398bb2 Compare June 7, 2026 01:12
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jun 7, 2026

Coverage Report for CI Build 4643

Coverage remained the same at 94.241%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15870
Covered Lines: 14956
Line Coverage: 94.24%
Coverage Strength: 207094.15 hits per line

💛 - Coveralls

@bobzhang bobzhang force-pushed the hongbo/warn-prefer-readonly-array branch 2 times, most recently from e7588dd to fe10350 Compare June 7, 2026 01:28
…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>
@bobzhang bobzhang force-pushed the hongbo/warn-prefer-readonly-array branch from fe10350 to ffc92ef Compare June 7, 2026 01:41
@bobzhang bobzhang merged commit d2de682 into main Jun 7, 2026
18 checks passed
@bobzhang bobzhang deleted the hongbo/warn-prefer-readonly-array branch June 7, 2026 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants