Skip to content

fix: enforce inline table and static array immutability#7

Merged
dereuromark merged 1 commit intomasterfrom
fix/inline-table-immutability
Mar 25, 2026
Merged

fix: enforce inline table and static array immutability#7
dereuromark merged 1 commit intomasterfrom
fix/inline-table-immutability

Conversation

@dereuromark
Copy link
Contributor

Summary

TOML spec requires that inline tables and static arrays (arrays defined via = [...]) are immutable and cannot be extended after definition. This PR enforces that constraint.

Changes

  • Add staticArrays tracking to reject extending array elements via table headers
  • Check sealed inline tables in openTable/openArrayTable before traversing
  • Track sealed tables within inline table scope for nested immutability validation
  • Update setNestedValue to accept scope-local sealed tables and static arrays

Fixed Cases

Test Issue
array/extending-table.toml a = [{}] then [a.b] now rejected
inline-table/overwrite-02.toml a = {} then [a.b] now rejected
inline-table/overwrite-07.toml { inner.table = [{}], inner.table.val = "x" } now rejected
inline-table/overwrite-08.toml { inner = {}, inner.cat = "x" } now rejected
inline-table/duplicate-key-03.toml Duplicate via dotted paths in inline table now rejected

Compliance

Version Invalid Tests Compliance
TOML 1.1 466/475 98.1%
TOML 1.0 466/483 96.5%

The 9 remaining failures for TOML 1.1 are strict TOML 1.0 tests for features that 1.1 relaxes (multiline inline tables, trailing commas, \xHH escapes, optional seconds).

TOML spec requires that inline tables and static arrays (arrays defined
via = [...]) are immutable and cannot be extended after definition.

Changes:
- Add static array tracking to reject extending array elements via table headers
- Check sealed inline tables in openTable/openArrayTable
- Track sealed tables within inline table scope for nested immutability
- Properly reject dotted key extensions of inline tables and static arrays

This fixes 5 toml-test invalid cases:
- array/extending-table.toml
- inline-table/overwrite-02.toml
- inline-table/overwrite-07.toml
- inline-table/overwrite-08.toml
- inline-table/duplicate-key-03.toml

Compliance: 98.1% invalid tests passing (TOML 1.1)
@dereuromark dereuromark merged commit 77c927b into master Mar 25, 2026
3 checks passed
@dereuromark dereuromark deleted the fix/inline-table-immutability branch March 25, 2026 06:02
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