Skip to content

Commit 40254ec

Browse files
committed
cmd/compile: fix wrong package path for unsafe.Pointer
It's not a predeclared type, but a type defined in "unsafe" package. Fixes #44830 Change-Id: If39815b1070059b608be8231dfac9b7f3307cb15 Reviewed-on: https://go-review.googlesource.com/c/go/+/313349 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 903b251 commit 40254ec

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/cmd/compile/internal/reflectdata/reflect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func typePkg(t *types.Type) *types.Pkg {
595595
}
596596
}
597597
}
598-
if tsym != nil && t != types.Types[t.Kind()] && t != types.ErrorType {
598+
if tsym != nil && tsym.Pkg != types.BuiltinPkg {
599599
return tsym.Pkg
600600
}
601601
return nil

test/fixedbugs/issue44830.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
import (
10+
"reflect"
11+
"unsafe"
12+
)
13+
14+
func main() {
15+
t := reflect.TypeOf(unsafe.Pointer(nil))
16+
if pkgPath := t.PkgPath(); pkgPath != "unsafe" {
17+
panic("unexpected t.PkgPath(): " + pkgPath)
18+
}
19+
}

0 commit comments

Comments
 (0)