Skip to content

import/path: issue title #69161

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
lvtuwjl opened this issue Aug 30, 2024 · 3 comments
Closed

import/path: issue title #69161

lvtuwjl opened this issue Aug 30, 2024 · 3 comments

Comments

@lvtuwjl
Copy link

lvtuwjl commented Aug 30, 2024

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/jianlilwang/Library/Caches/go-build'
GOENV='/Users/jianlilwang/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/jianlilwang/go/pkg/mod'
GONOPROXY='chainmaker.org,git.woa.com,git.code.tencent.com,chainweaver.org.cn'
GONOSUMDB='chainmaker.org,git.woa.com,git.code.tencent.com,chainweaver.org.cn'
GOOS='darwin'
GOPATH='/Users/jianlilwang/go'
GOPRIVATE='chainmaker.org,git.woa.com,git.code.tencent.com,chainweaver.org.cn'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/b8/xgq9vmyx22z327lfq3x13_780000gn/T/go-build1248346596=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

json marshal output not expect

package main

import (
	"encoding/json"
	"fmt"
	"log"
)

func main() {
	c := &C{
		Age:  30,
		Addr: "shanghai",
		A: A{
			Age:  10,
			Name: "aa",
		},
		B: B{
			Age:  20,
			Name: "bb",
		},
	}

	b, err := json.Marshal(c)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("b:", string(b))
	// Output:
	// b: {"age":30,"addr":"shanghai"}
}

type A struct {
	Age  int    `json:"age"`
	Name string `json:"name"`
}

type B struct {
	Age  int    `json:"age"`
	Name string `json:"name"`
}

type C struct {
	Age  int    `json:"age"`
	Addr string `json:"addr"`
	A
	B
}

What did you see happen?

{"age":30,"addr":"shanghai"}

What did you expect to see?

{"age":30,"addr":"shanghai","name":"bb"}

@seankhliao
Copy link
Member

This is the same as go field promotion, if there are conflicts in embedded structs, neither is promoted.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 30, 2024
@lvtuwjl
Copy link
Author

lvtuwjl commented Aug 30, 2024

This is the same as go field promotion, if there are conflicts in embedded structs, neither is promoted.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants