Skip to content

Fix the parameter callout on the mutating trimPrefix(while:) - #287

Open
hxperl wants to merge 1 commit into
apple:mainfrom
hxperl:trimprefix-parameter-callout
Open

Fix the parameter callout on the mutating trimPrefix(while:)#287
hxperl wants to merge 1 commit into
apple:mainfrom
hxperl:trimprefix-parameter-callout

Conversation

@hxperl

@hxperl hxperl commented Sep 11, 2026

Copy link
Copy Markdown

What's wrong

Sources/Algorithms/Trim.swift:83, on the Collection where Self == Self.SubSequence
overload of trimPrefix(while:), writes the parameter callout with a plural
Parameters:

/// - Parameters predicate: A closure that determines if the element should
///   be removed from the string.

DocC treats - Parameters as the header of a nested parameter list, not as a
- Parameter <name>: entry. No nested list follows, so the entry binds to nothing
and — this is the part that matters — the description is not merely misplaced, it is
dropped from the rendered page entirely. The method documents one parameter and
ends up showing none.

The other eight parameter callouts in this file already use the singular form,
including the near-identical overload 25 lines above, so the file contradicts itself.

Reproduction

On main at 5b7143f8e291dee0e14c118fd0212487f0b37af5, before changing anything.
The two trimPrefix(while:) overloads are an unusually clean control pair — DocC
renders their declarations identically, so the only variable is the callout spelling:

swift build --target Algorithms \
  -Xswiftc -emit-symbol-graph \
  -Xswiftc -emit-symbol-graph-dir -Xswiftc /tmp/sg \
  -Xswiftc -emit-extension-block-symbols
xcrun docc convert --fallback-display-name Algorithms \
  --fallback-bundle-identifier org.swift.Algorithms \
  --additional-symbol-graph-dir /tmp/sg --output-path /tmp/out.doccarchive

data/documentation/algorithms/swift/collection/:

trimprefix(while:)-2r8n8.json        <- the `- Parameter` sibling
  decl:     mutating func trimPrefix(while predicate: (Element) throws -> Bool) rethrows
  sections: ['declarations', 'parameters', 'content']
  PARAM 'predicate': A closure that determines if the element should be removed from the result.

trimprefix(while:)-93obt.json        <- this one
  decl:     mutating func trimPrefix(while predicate: (Element) throws -> Bool) rethrows
  sections: ['declarations', 'content']

No parameters section. Grepping the rendered pages for the description text:

closure that determines  in trimprefix(while:)-93obt.json : 0
closure that determines  in trimprefix(while:)-2r8n8.json : 1

The Discussion of the affected page contains only the heading, the example
paragraph, the code listing and the Complexity aside — the parameter text is not in
it. The - Complexity: aside is unaffected and still renders correctly.

Note that -emit-extension-block-symbols is required to reproduce: trimPrefix(while:)
extends a stdlib protocol, so without it the page is not generated at all and there is
nothing to inspect. That is also why this is easy to miss.

Worth stating plainly: DocC emits no diagnostic for this. docc convert exits 0
with an empty warning list. The rendered output is the only evidence.

After

Same commands on this branch:

trimprefix(while:)-2r8n8.json -> ['declarations', 'parameters', 'content']
   PARAM 'predicate': A closure that determines if the element should be removed from the result.
trimprefix(while:)-93obt.json -> ['declarations', 'parameters', 'content']
   PARAM 'predicate': A closure that determines if the element should be removed from the string.

Scope

One word, one line. This is the only occurrence in the repository — I grepped
Sources/ and Tests/ for - Parameters <name>: and for backticked parameter names
(the other way DocC silently fails to bind a parameter) and found nothing else.

Tests

swift test on macOS 15 arm64, Swift 6.2:

Executed 224 tests, with 0 failures (0 unexpected) in 1.854 (1.883) seconds

Exit code 0. For a comment-only change this is a regression check rather than evidence
for the fix — the rendered DocC output above is the evidence. macOS only; CI will need
to confirm the other platforms, though I would not expect a doc-comment change to
differ by platform.

Disclosure

This change was written with AI assistance. The reproduction, the DocC runs and the
test output above are real output from my machine, not generated text.

The `Collection where Self == Self.SubSequence` overload of
`trimPrefix(while:)` writes its parameter callout as
`- Parameters predicate:` — plural `Parameters`, which DocC reads as the
header of a nested parameter list rather than as a `- Parameter <name>:`
entry. Because no nested list follows, the entry binds to nothing and the
description is dropped from the rendered page entirely: the method shows no
Parameters section at all.

The other eight callouts in this file, including the near-identical
overload 25 lines above, already use the singular form.
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