Skip to content

render: formatCanonicalNumber's doc comment still says grouping is "stripped unconditionally" and "never accepted back on entry" — morph#574 made both false #597

Description

@Yaraslaut

Found while fixing #583. Filed rather than folded in, per AGENTS.md: it is a
stale claim about grouping, left behind by #574/#581, and has nothing to do
with the sign change #583 is about.

Verification status: reproduced by reading the code, against real output

Revision: 992b190c (current master). The contradiction is textual, so "read
the code" is the whole of it — but the behaviour the comment describes is
measured below, not assumed.

include/morph/render/locale_format.hpp, the Doxygen block on
formatCanonicalNumber:

/// The display-direction inverse of `normalizeLocaleNumber`'s
/// decimal-separator substitution, plus display-only thousands grouping
/// (grouping is never accepted back on entry — `normalizeLocaleNumber`
/// strips it unconditionally). Passing `decimalSeparator == "."` and an empty
/// @p groupSeparator is the identity transform.

Both halves of the parenthetical are now false:

  1. "grouping is never accepted back on entry" — it is. A correctly placed
    group separator normalises:

    normalizeLocaleNumber("1.050,25",     dec=",", grp=".")  -> "1050.25"
    normalizeLocaleNumber("1.000.000,25", dec=",", grp=".")  -> "1000000.25"
    

    (tests/test_render_locale_format.cpp, "every well-formed locale entry still
    normalises", pins exactly this.)

  2. "strips it unconditionally" — that is precisely what morph#574 stopped it
    doing, three doc paragraphs earlier in the same header, under the heading
    "Grouping is validated, not stripped (morph#574)". A misplaced separator
    is now rejected:

    normalizeLocaleNumber("1.5",     dec=",", grp=".")  -> NULLOPT
    normalizeLocaleNumber("1.2.3.4", dec=",", grp=".")  -> NULLOPT
    

git log -S "strips it unconditionally" dates the sentence to d2cb3ae1, long
before #574 — so this is a doc comment that was correct when written and was not
updated when the behaviour it describes was deliberately reversed.

docs/spec/forms/forms.md, "Locale data formatting", has the correct account
("Grouping is validated, never merely stripped."), so the spec and the header
disagree, with the header wrong. Per AGENTS.md that makes the header the thing to
change, not the spec.

Why it matters at all

It is only a comment — no behaviour depends on it. But it is the comment a reader
hits when deciding whether formatCanonicalNumber's output can be fed back
through normalizeLocaleNumber, and it tells them the round trip does not hold
when it does. The whole point of the #574 work was that the grouping contract is
the thing people get wrong.

Fix

Delete or rewrite the parenthetical, e.g. "grouping is validated on the way back
in — see normalizeLocaleNumber — so a grouped display round-trips". A one-line
documentation change with no behavioural component.

What would change the verdict

Close it when the comment no longer claims either of the two false things. Re-open
only if normalizeLocaleNumber is ever changed back to stripping grouping
unconditionally, which #574 exists to prevent.

Not verified here

Whether the same stale claim appears anywhere else in the tree. Grepped for the
exact phrase — "strips it unconditionally" occurs once, in this header — but
not for paraphrases of it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsSubsystem: formsdocumentationImprovements or additions to documentationtriage: validWell-framed; implement as written

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions