Skip to content

Keep null elements in typed sequences - #503

Open
ViktorBystrov72 wants to merge 1 commit into
yaml:mainfrom
ViktorBystrov72:fix-null-sequence-elements
Open

ViktorBystrov72 wants to merge 1 commit into
yaml:mainfrom
ViktorBystrov72:fix-null-sequence-elements

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Decoding [before, null, after] into []string currently returns ["before", "after"]. Omitted block-sequence entries disappear in the same way, and fixed-size arrays move later values into the wrong slots. This affects the positional data described in go-yaml/yaml#1011 and go-yaml/yaml#1063, and still reproduces on v4 main.

Keep the already initialized zero-value element when construction returns false for a null node. This preserves the sequence position for element types that cannot hold nil, including aliases of null. Invalid non-null values still follow the existing error path.

The regression covers strings, integers, booleans, structs, fixed-size arrays, omitted entries, and null aliases through both Load and Unmarshal. Fourteen assertions fail before the fix and pass afterward. Interface and pointer slice cases verify that existing nil elements are preserved.

Validation on macOS arm64:

  • make fmt, make tidy, make lint, and make lint-yaml pass.
  • make test opts=-race passes using the makefile's pinned Go 1.27.2, including CLI integration and release-script tests. YAML Test Suite results: 1542 passing comparisons and 66 expected known failures.
  • Public and internal/libyaml tests pass with Go 1.18.10, the supported minimum series.
  • The go-yaml -t CLI confirms that the omitted sequence entries reach the constructor; git diff --check passes.

The change targets v4 only, in accordance with the maintenance policy for v2/v3.

Null values cannot be assigned to non-nillable elements, so sequence
construction currently drops them and shifts later values to earlier
indices. Retain their zero-value slots for slices and arrays, including
omitted entries and aliases of null.

Signed-off-by: Виктор Быстров <anatema@bk.ru>
@ViktorBystrov72
ViktorBystrov72 force-pushed the fix-null-sequence-elements branch from 1cecf68 to 544247d Compare November 23, 2026 11:15
@ingydotnet

Copy link
Copy Markdown
Member

@ViktorBystrov72 can you redo the tests for this using our testdata/ style testing?

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