8000 ReflectFrom with embeded structs panics · Issue #61 · go-ini/ini · GitHub
[go: up one dir, main page]

Skip to content

ReflectFrom with embeded structs panics #61

Closed

Description

@andreynering

Reproduce script:

package main

import (
    "bytes"
    "fmt"

    "gopkg.in/ini.v1"
)

type Struct1 struct {
    Field1 string
}

type Struct2 struct {
    Struct1
}

func main() {
    v := Struct2{Struct1{"foobar"}}

    cfg := ini.Empty()
    if err := cfg.ReflectFrom(&v); err != nil {
        fmt.Printf("Ops: %v", err)
    }

    buff := bytes.NewBuffer(nil)
    cfg.WriteTo(buff)
    fmt.Println(buff.String())
}

The above gives the following output:

panic: interface conversion: interface is main.Struct1, not time.Time

goroutine 1 [running]:
panic(0x5166c0, 0x10a6bbe0)
        C:/GOROOT/src/runtime/panic.go:481 +0x326
gopkg.in/ini%2ev1.reflectWithProperType(0x8d4068, 0x514f20, 0x10a6bbc0, 0x514f20, 0x10a88168, 0x199, 0x52c970, 0x1, 0x0, 0x0)
        D:/Go/src/gopkg.in/ini.v1/struct.go:318 +0x30a
gopkg.in/ini%2ev1.(*Section).reflectFrom(0x10a66390, 0x514f80, 0x10a88168, 0x199, 0x0, 0x0)
        D:/Go/src/gopkg.in/ini.v1/struct.go:393 +0x72a
gopkg.in/ini%2ev1.(*Section).ReflectFrom(0x10a66390, 0x4ebd80, 0x10a88168, 0x0, 0x0)
        D:/Go/src/gopkg.in/ini.v1/struct.go:412 +0x149
gopkg.in/ini%2ev1.(*File).ReflectFrom(0x10a68580, 0x4ebd80, 0x10a88168, 0x0, 0x0)
        D:/Go/src/gopkg.in/ini.v1/struct.go:417 +0x51
main.main()
        C:/Users/andrey.nering/Desktop/ini_reproduce.go:22 +0x93
exit status 2

I guess the error started after 959d90a

I suspect from this and this lines.

Given that reflect.TypeOf(time.Now()).Kind() is struct, so any struct will match that line. See https://play.golang.org/p/16o9O2eDNq

Checkouting to 927d8d7 (one commit before the cited) fixed this issue for me.

Activity

  1. unknwon commented on Aug 5, 2016

    @unknwon
    Member

    Which version of Go?

  2. andreynering commented on Aug 5, 2016

    @andreynering
    Author

    1.6.2

  3. added a commit that references this issue on Aug 5, 2016
  4. unknwon commented on Aug 5, 2016

    @unknwon
    Member

    Fix pushed.

  5. andreynering commented on Aug 5, 2016

    @andreynering
    Author

    Thanks for the fast fix. I'll test when possible and give feedback.

  6. andreynering commented on Aug 6, 2016

    @andreynering
    Author

    It's working. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0