gccgo: wrong PkgPath for embedded struct field in package main #10173

Closed
h4ck3rm1k3 opened this Issue Mar 16, 2015 · 6 comments

Comments

Projects
None yet
4 participants

found this error porting https://github.com/metaleap/go-xsd to gcccode.

It seems that the reflection is failing here. The sub object is private but the field contained is public.
This is different in gccgo than go playground.

package main
import "fmt"
import "encoding/xml"
type hasFoo3 struct {
    Blah3 int
}
type Foo struct {
    hasFoo3 
}
func main() {
    fmt.Println("Hello, playground")
    var encoded []byte
    var err error
    var vP Foo
    encoded, err = xml.Marshal(vP)
    fmt.Printf("%s err:%v\n", encoded, err)
    err = xml.Unmarshal(encoded, &vP)
    fmt.Printf("Unmarshal %v %s", vP, err)
}

see https://play.golang.org/p/w_FzGI3LvW
Output with the playground

Hello, playground
<Foo><Blah3>0</Blah3></Foo> err:<nil>
Unmarshal {{0}} %!s(<nil>)

output with gcc-go-5

Hello, playground
<Foo></Foo> err:<nil>
Unmarshal {{0}} %!s(<nil>)

using gccgo-5 (Debian 5-20150226-1) 5.0.0 20150226 (experimental) [trunk revision 220999]

@ianlancetaylor you want a bugzilla for this?

Member

minux commented Mar 16, 2015

@minux minux changed the title from GCCGO encoding/xml problem with reflecting to gccgo: wrong PkgPath for embedded struct field in package main Mar 16, 2015

I had already hacked that code to return "" and it causes a reflection error on the access of a private method later on.

Using this version of encoding with all types of print statements added
https://github.com/h4ck3rm1k3/google-go/tree/hack-xml
https://github.com/h4ck3rm1k3/google-go/blob/hack-xml/src/encoding/xml/read.go#L628

panic: reflect: unknown method using value obtained using unexported field

goroutine 16 [running]:
xml.copyValue
    encoding2/xml/read.go:628 
go.xml.unmarshalAttr.pN14_go.xml.Decoder
    encoding2/xml/read.go:265
go.xml.unmarshal.pN14_go.xml.Decoder
    encoding2/xml/read.go:453
go.xml.DecodeElement.pN14_go.xml.Decoder
    encoding2/xml/read.go:137
go.xml.Decode.pN14_go.xml.Decoder
    encoding2/xml/read.go:123
go.xml.Unmarshal
    encoding2/xml/read.go:116
Contributor

mwhudson commented Mar 16, 2015

Isn't this the same problem as #7247?

Member

minux commented Mar 16, 2015

Yes.

@minux minux closed this Mar 16, 2015

Even if you turn that flag off you will still get problems. Will have to research this more.

@gopherbot gopherbot locked and limited conversation to collaborators Jun 25, 2016

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