Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some specially structured structs produce results that cannot be resolved #438

Open
peakedshout opened this issue Feb 20, 2025 · 1 comment

Comments

@peakedshout
Copy link

It's not clear to me why there is an extra "symbol", which causes the result to be unresolvable.

type T struct {
	Ts [][]T1
}

type T1 struct {
	A   string
	T2s *T2
}

type T2 struct {
	D string `json:"d"`
}

func main() {
	t := T{
		Ts: [][]T1{
			{
				{
					A:   "TTTT",
					T2s: &T2{D: "dwd"},
				},
			},
		},
	}
	bs, err := toml.Marshal(t)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(bs)) //Ts = [[{A = "TTTT"T2s = {D = "dwd"}, }]]
}
@arp242
Copy link
Collaborator

arp242 commented Feb 20, 2025

Slightly simpler test case:

package main

import (
	"fmt"

	"github.com/BurntSushi/toml"
)

type (
	Top struct {
		T [][]T
	}
	T struct {
		A string
		B map[string]string
	}
)

func main() {
	bs, err := toml.Marshal(Top{
		T: [][]T{{{
			A: "TTTT",
			B: map[string]string{"a": "b"},
		}}},
	})
	fmt.Println(err)
	fmt.Println(string(bs))
}

% go run main.go
<nil>
T = [[{A = "1"B = {2 = "3"}, }]]

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

No branches or pull requests

2 participants