pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.69k stars 206 forks source link

panic: reflect: NumField of non-struct type #807

Closed bep closed 2 years ago

bep commented 2 years ago
package main

import (
    "fmt"
    "log"

    "github.com/pelletier/go-toml/v2"
)

type A struct {
    Name string `toml:"name"`
}

type M struct {
    *A
}

func main() {
    var m M
    err := toml.Unmarshal([]byte(`name = 'foo'`), &m)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Name is %s", m.Name)
}

The above panics with panic: reflect: NumField of non-struct type *main.A.

https://go.dev/play/p/8GRYRf8lbvz

The same set up runs fine using encoding/json:

https://go.dev/play/p/bLAXgWtFlv4

pelletier commented 2 years ago

Thanks for reporting it!

pelletier commented 2 years ago

Should be fixed as of https://github.com/pelletier/go-toml/commit/e46d245c090232c37469a70ca74b6dd8dbc47f16. Let me know if you encounter any issue!