Skip to content

fix(fmt): format maps and function types as Go does - #548

Merged
paralin merged 1 commit into
s4wave:devfrom
cogentcore:fix/fmt-maps-func-types
Oct 25, 2026
Merged

paralin merged 1 commit into
s4wave:devfrom
cogentcore:fix/fmt-maps-func-types

Conversation

@rcoreilly

Copy link
Copy Markdown
Contributor

fmt formatted a map as {k:v ...} in insertion order, where Go writes map[k:v ...] with the entries sorted by key, and %T of a function value gave "function".

A map now formats as map[k:v ...], with its key and element types passed down for formatting the entries, and its entries sorted as Go's internal/fmtsort sorts them: numbers by value with NaN first, strings lexically, false before true, arrays and structs element by element. %#v writes the map in Go syntax, map[string]int{"a":1, "b":2}.

typeInfoGoString now spells function types, func(int, ...string) (bool, error), and the empty interface, so %T of a function value gives its signature, and %#v of a nil func its type.

fmt_map_sorted and fmt_type_func check these against Go, and the fmt unit test of map formatting now expects Go's output.

fmt formatted a map as {k:v ...} in insertion order, and %T of a function value as function.

A map now formats as map[k:v ...], with its entries sorted by key as Go's fmt sorts them, and in Go syntax for %#v. The Go type string of a type info now spells function types and the empty interface, which %T gives for a function value, and %#v for a nil function.

Signed-off-by: Randall C. O'Reilly <oreilly@ucdavis.edu>
@paralin
paralin changed the base branch from master to dev October 25, 2026 18:38
@paralin
paralin merged commit 4371baf into s4wave:dev Oct 25, 2026
7 checks passed
@paralin

paralin commented Oct 25, 2026

Copy link
Copy Markdown
Member

Landed on master as 87753a2, rebased onto the batch #532 to #550, with regenerated fixtures in fca8071.

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