Don't crash when assigning group array to array
diff --git a/parser.go b/parser.go index c3afa04..ba95fa5 100644 --- a/parser.go +++ b/parser.go
@@ -107,7 +107,7 @@ var array []*TomlTree if destTree == nil { array = make([]*TomlTree, 0) - } else if destTree.([]*TomlTree) != nil { + } else if target, ok := destTree.([]*TomlTree); ok && target != nil { array = destTree.([]*TomlTree) } else { p.raiseError(key, "key %s is already assigned and not of type group array", key)
diff --git a/parser_test.go b/parser_test.go index 0532d61..4481e67 100644 --- a/parser_test.go +++ b/parser_test.go
@@ -626,3 +626,10 @@ t.Error("Bad error message:", err.Error()) } } + +func TestGroupArrayReassign(t *testing.T) { + _, err := Load("[hello]\n[[hello]]") + if err.Error() != "(2, 3): key \"hello\" is already assigned and not of type group array" { + t.Error("Bad error message:", err.Error()) + } +}