Skip to content

Commit 0779b5f

Browse files
authored
toml: fix implicit array allocation (#12553)
1 parent 49cd1b3 commit 0779b5f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

vlib/toml/parser/parser.v

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,16 +776,19 @@ pub fn (mut p Parser) double_array_of_tables(mut table map[string]ast.Value) ? {
776776
// Implicit allocation
777777
if p.last_aot.len == 0 {
778778
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'implicit allocation of array for dotted key `$dotted_key`.')
779-
table[first.str()] = []ast.Value{}
780779
p.last_aot = first
781780
// We register this implicit allocation as *explicit* to be able to catch
782781
// special cases like:
783782
// https://github.com/BurntSushi/toml-test/blob/576db852/tests/invalid/table/array-implicit.toml
784783
p.explicit_declared << first
785784

786-
t_arr = &(table[p.last_aot.str()] as []ast.Value)
787-
t_arr << ast.Value(map[string]ast.Value{})
788-
p.last_aot_index = t_arr.len - 1
785+
mut nm := map[string]ast.Value{}
786+
nm[last.str()] = []ast.Value{}
787+
table[first.str()] = ast.Value(nm)
788+
789+
t_arr = &(nm[last.str()] as []ast.Value)
790+
t_arr << p.array_of_tables_contents() ?
791+
return
789792
} else {
790793
return error(@MOD + '.' + @STRUCT + '.' + @FN +
791794
' nested array of tables key "$first" does not match "$p.last_aot". (excerpt): "...${p.excerpt()}..."')

vlib/toml/tests/burntsushi.toml-test_test.v

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ const (
1717
valid_value_exceptions = [
1818
// Integer
1919
'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808')
20-
// Table
21-
'table/array-implicit.toml',
2220
// Date-time
2321
'datetime/milliseconds.toml',
2422
// Key

0 commit comments

Comments
 (0)