Skip to content

import/path: issue title #73371

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
intchar-hub opened this issue Apr 14, 2025 · 2 comments
Closed

import/path: issue title #73371

intchar-hub opened this issue Apr 14, 2025 · 2 comments
Labels
Other None of the above.

Comments

@intchar-hub
Copy link

intchar-hub commented Apr 14, 2025

Go version

go version go1.23.8 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/bytedance/Library/Caches/go-build'
GOENV='/Users/bytedance/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/bytedance/go/pkg/mod'
GONOPROXY='*.byted.org,*.everphoto.cn,git.smartisan.com'
GONOSUMDB='*.byted.org,*.everphoto.cn,git.smartisan.com'
GOOS='darwin'
GOPATH='/Users/bytedance/go'
GOPRIVATE='*.byted.org,*.everphoto.cn,git.smartisan.com'
GOPROXY='https://goproxy.byted.org|https://goproxy.cn|direct'
GOROOT='/Users/bytedance/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.8.darwin-arm64'
GOSUMDB='sum.golang.google.cn'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/bytedance/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.8.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.8'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/bytedance/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
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'

What did you do?

package main

type Person struct {
	Name      string
	Age       int
	TestSlice []string
}

// main demo5 - 测试 marshal 和 unmarshal 方法对 nil 值的实践
func main() {
	pList1 := []Person{
		{
			Name: "1",
		},
		{
			Name: "2",
		},
	}
	pList2 := []Person{
		{
			Name: "3",
		},
		{
			Name: "4",
		},
	}
	println("1111", &pList1, &pList2, &pList1[0])
	test(pList1, pList2)
	println("1111", &pList1, &pList2, &pList1[0])
}

func test(personList ...[]Person) {
	println(&personList[0], &personList[1], &personList[0][0])
	for _, persons := range personList {
		for i := range persons {
			persons[i].Name = "test"
		}
	}
	testPerson := []Person{
		{
			Name: "5",
		},
	}
	println("2222", &testPerson)
	personList[0] = testPerson
}

What did you see happen?

1111 0x14000050628 0x14000050610 0x14000050640
0x140000506a8 0x140000506c0 0x14000050640
2222 0x1400009cdf8
1111 0x1400009ce28 0x1400009ce10 0x1400009ce40

What did you expect to see?

After calling the test function, the addresses of pList1 and pList2 do not change.
However, if the following lines:

println(&personList[0], &personList[1], &personList[0][0])
println("2222", &testPerson)

are omitted, the addresses of pList1 and pList2 are the same.

@randall77
Copy link
Contributor

What makes you think the addresses won't change?

We do stack copying, so if plist1 and plist2 are on the stack, their addresses will change.

@gabyhelp gabyhelp added the Other None of the above. label Apr 14, 2025
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Other None of the above.
Projects
None yet
Development

No branches or pull requests

4 participants