]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix wrong package path for unsafe.Pointer
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sun, 25 Apr 2021 08:46:30 +0000 (15:46 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 27 Apr 2021 01:16:39 +0000 (01:16 +0000)
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 <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/reflectdata/reflect.go
test/fixedbugs/issue44830.go [new file with mode: 0644]

index d23ca6b839e60e334c322529ce87d1a393ce12ff..26b08ee08a2a15248b6abc349c7ccb7320a0277f 100644 (file)
@@ -595,7 +595,7 @@ func typePkg(t *types.Type) *types.Pkg {
                        }
                }
        }
-       if tsym != nil && t != types.Types[t.Kind()] && t != types.ErrorType {
+       if tsym != nil && tsym.Pkg != types.BuiltinPkg {
                return tsym.Pkg
        }
        return nil
diff --git a/test/fixedbugs/issue44830.go b/test/fixedbugs/issue44830.go
new file mode 100644 (file)
index 0000000..7df5aeb
--- /dev/null
@@ -0,0 +1,19 @@
+// run
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "reflect"
+       "unsafe"
+)
+
+func main() {
+       t := reflect.TypeOf(unsafe.Pointer(nil))
+       if pkgPath := t.PkgPath(); pkgPath != "unsafe" {
+               panic("unexpected t.PkgPath(): " + pkgPath)
+       }
+}