Arrays of tables are allowed to extend static arrays when nested inside another array of tables #495
Open
Description
When parsing, taplo
correctly forbids extending a static array using an array of tables, but only if those arrays are not themselves inside an array of tables.
By my read of the TOML spec, being inside an array of tables as well shouldn't change whether this is valid. The other two TOML parsers I've run this through consider it invalid regardless of context; tomllib
in Python's standard library produces the error "Cannot mutate immutable namespace" and https://www.toml-lint.com/ the error "Can't extend an inline array".
In the example below, I've created three invalid TOML files. All three of them contain a static array and an array of tables, both named fruits
, but in different contexts:
invalid1.toml
has them in the root table. This is recognized as invalid bytaplo
.invalid2.toml
has them nested inside a table namedfood
. This is recognized as invalid bytaplo
.invalid3.toml
has them nested inside an array of tables namedfood
. This is considered valid bytaplo
, with the tables appended to the static array.
The result of running those three files through taplo get -o json
$ cat invalid1.toml
fruits = ["one", "two"]
[[fruits]]
three = "four"
$ npx @taplo/cli get -o json < invalid1.toml
error: expected array of tables
┌─ -:1:1
│
1 │ fruits = ["one", "two"]
│ ^^^^^^ expected array of tables
2 │
3 │ [[fruits]]
│ ------ required by this key
ERROR operation failed error=semantic errors found
$ cat invalid2.toml
[food]
fruits = ["one", "two"]
[[food.fruits]]
three = "four"
$ npx @taplo/cli get -o json < invalid2.toml
error: expected array of tables
┌─ -:2:1
│
2 │ fruits = ["one", "two"]
│ ^^^^^^ expected array of tables
3 │
4 │ [[food.fruits]]
│ ------ required by this key
ERROR operation failed error=semantic errors found
$ cat invalid3.toml
[[food]]
fruits = ["one", "two"]
[[food.fruits]]
three = "four"
$ npx @taplo/cli get -o json < invalid3.toml
{
"food": [
{
"fruits": [
"one",
"two",
{
"three": "four"
}
]
}
]
}