Skip to content

docs: 数组章节使用 comptime 标签块初始化 fancy_array - #363

Merged
jiacai2050 merged 3 commits into
mainfrom
comptime_array
Aug 7, 2026
Merged

docs: 数组章节使用 comptime 标签块初始化 fancy_array#363
jiacai2050 merged 3 commits into
mainfrom
comptime_array

Conversation

@xihale

@xihale xihale commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Documentation
    • Updated array initialization examples across course lessons and the release example.
    • Examples now explicitly evaluate array initialization at compile time and verify the final element.
    • Added an online Compiler Explorer example to the compile-time array initialization guide.
    • Improved consistency and accuracy when demonstrating compile-time array construction.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6b651119-d5c2-4842-9d84-73ad59d64c6c

📥 Commits

Reviewing files that changed from the base of the PR and between 527fb47 and fd4b40f.

📒 Files selected for processing (1)
  • course/basic/advanced_type/array.md

📝 Walkthrough

Walkthrough

The array examples in course versions 11, 12, 14, 15, 16, and release now explicitly evaluate their labeled fancy_array initialization blocks at compile time and verify the final element. The documentation adds a Compiler Explorer example link.

Changes

Array initialization examples

Layer / File(s) Summary
Explicit compile-time array initialization
course/code/{11,12,14,15,16}/array.zig, course/code/release/array.zig
The fancy_array initialization blocks now use explicit compile-time evaluation. Each example adds an assertion that fancy_array[9] equals 9.
Compiler Explorer example link
course/basic/advanced_type/array.md
The compile-time array initialization documentation now includes a Compiler Explorer link.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: jiacai2050, jinzhongjia

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了数组章节使用 comptime 标签块初始化 fancy_array 的主要变更。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch comptime_array

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
course/code/16/array.zig (1)

126-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an assertion for the computed array.

This example contains logic that can be validated with a meaningful assertion. Add a test that checks all ten values are 0 through 9. Do not test only that printing succeeds.

Based on learnings: Zig examples under course/code/16/ should add tests when the example contains logic that can be validated with meaningful assertions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@course/code/16/array.zig` at line 126, Add a test for the comptime-computed
fancy_array initialized by the init block, asserting that it contains exactly
ten elements with values 0 through 9 in order. Ensure the test validates the
array contents rather than only exercising its printing.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@course/code/15/array.zig`:
- Line 126: Add focused unit tests for the compile-time array initializer around
fancy_array in course/code/15/array.zig at lines 126-126, while preserving its
pub fn main() requirement, and in course/code/16/array.zig at lines 126-126 add
assertions verifying all ten values are 0 through 9; validate the array contents
directly rather than testing printed output.

---

Nitpick comments:
In `@course/code/16/array.zig`:
- Line 126: Add a test for the comptime-computed fancy_array initialized by the
init block, asserting that it contains exactly ten elements with values 0
through 9 in order. Ensure the test validates the array contents rather than
only exercising its printing.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a5b16ff7-67ef-4ca4-a72f-3b109869178f

📥 Commits

Reviewing files that changed from the base of the PR and between 4bfbf18 and a2d27de.

📒 Files selected for processing (6)
  • course/code/11/array.zig
  • course/code/12/array.zig
  • course/code/14/array.zig
  • course/code/15/array.zig
  • course/code/16/array.zig
  • course/code/release/array.zig

Comment thread course/code/15/array.zig
Comment thread course/code/11/array.zig

pub fn main() void {
const fancy_array = init: {
const fancy_array = comptime init: {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

可以吧这个链接也加到文档的正文中,方便读者看结果。

@jiacai2050
jiacai2050 merged commit cde4db3 into main Aug 7, 2026
21 checks passed
@jiacai2050
jiacai2050 deleted the comptime_array branch August 7, 2026 09:35
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