Skip to content

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

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

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

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

h4ck3rm1k3 opened this issue Mar 16, 2015 · 6 comments

Comments

@h4ck3rm1k3
Copy link

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]

@h4ck3rm1k3
Copy link
Author

@ianlancetaylor you want a bugzilla for this?

@minux
Copy link
Member

minux commented Mar 16, 2015 via email

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

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

@mwhudson
Copy link
Contributor

Isn't this the same problem as #7247?

@minux
Copy link
Member

minux commented Mar 16, 2015

Yes.

@minux minux closed this as completed Mar 16, 2015
@h4ck3rm1k3
Copy link
Author

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

@golang golang 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.
Projects
None yet
Development

No branches or pull requests

4 participants