Skip to content

Make the guide's guard example print what it shows - #140

Open
quinnj-bot[bot] wants to merge 1 commit into
mainfrom
claude/docs-guard-example
Open

quinnj-bot[bot] wants to merge 1 commit into
mainfrom
claude/docs-guard-example

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Why

The guide's guard example shows output that its code does not produce, and it teaches a pattern that silently matches everything. In the example, nothing is an identifier, so ("-h" || "--help", nothing) binds a new variable named nothing and matches any second value. ("-l", lang) matches ("-l", nothing), so parse_arg("-l") prints Language set to nothing, not the Unknown argument: ("-l",nothing) the guide shows.

What changed

  • Both versions of the parse_arg example use lang::String and ::Nothing, so every shown output is what the code prints. The test suite's copy of this example already guards lang the same way.
  • The shown tuples use the current printing (("-l", nothing)).
  • A new item under "Notes/Gotchas" says that nothing, missing and NaN are identifiers in a pattern, and how to match the constant itself (::Nothing, ::Missing, $(NaN)).

Verification

I extracted both parse_arg versions from docs/src/index.md and ran them on Julia 1.12.6. With this branch, every call prints the line the guide shows, and both versions agree:

("-l", "eng")    Language set to eng
("-l",)          Unknown argument: ("-l", nothing)
("-o", 1.0)      Unknown argument: ("-o", 1.0)
("-h",)          Help!
("-h", 5)        Unknown argument: ("-h", 5)

With main's version, parse_arg("-l") prints Language set to nothing and parse_arg("-h", 5) prints Help!.

🤖 Generated with Claude Code

nothing in a pattern is an identifier that binds a variable, so the
example's ("-h" || "--help", nothing) case matched any value and
("-l", lang) matched ("-l", nothing). Use ::Nothing and lang::String,
update the shown tuple printing, and note under Notes/Gotchas how to
match named constants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (f26639b) to head (d186c5d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #140   +/-   ##
=======================================
  Coverage   99.38%   99.38%           
=======================================
  Files          12       12           
  Lines        1132     1132           
=======================================
  Hits         1125     1125           
  Misses          7        7           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant