Skip to content

import/path: issue title #73371

@intchar-hub

Description

@intchar-hub

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    OtherNone of the above.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions