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

encoding/xml: XMLName value of embedded structs type not used in Marshaller #38260

Open
lunicon opened this issue Apr 5, 2020 · 2 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@lunicon
Copy link

lunicon commented Apr 5, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14.1 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Constantine\AppData\Local\go-build
set GOENV=C:\Users\Constantine\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\Develop\golib
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\Develop\go1.14.1
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Develop\go1.14.1\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\CONSTA~1\AppData\Local\Temp\go-build125187114=/tmp/go-build -gno-record-gcc-switches

What did you do?

Try to use XMLName in embedded type play stackoverflow

type XMLForm struct {
	XMLName xml.Name
}
type Test struct {
	XMLForm
}
var t Test
t.XMLName.Local = "c:test"

xml.Marshal(&t)

What did you expect to see?

<c:test></c:test>

What did you see instead?

<Test></Test>

It fails on go1.14.1\src\encoding\xml\marshal.go: can't cast to xml.Name

482: } else if v, ok := xmlname.value(val).Interface().(Name); ok && v.Local != "" {
483:       start.Name = v
484: }

I also find a reason for this error https://golang.org/src/encoding/xml/typeinfo.go
Need to add idx of embed type to slice

78:   if tinfo.xmlname == nil {
++                                        && inner.xmlname != nil {
79:      tinfo.xmlname = inner.xmlname
++      tinfo.xmlname.idx = append([]int{i}, inner.xmlname.idx...)
80:   }
@andybons andybons changed the title XMLName value of embedded structs type not used in Marshaller encoding/xml: XMLName value of embedded structs type not used in Marshaller Apr 6, 2020
@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 6, 2020
@andybons andybons added this to the Unplanned milestone Apr 6, 2020
@seankhliao

This comment was marked as outdated.

@lunicon

This comment was marked as resolved.

@seankhliao seankhliao reopened this Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants