Skip to content

Commit 24aca17

Browse files
committed
cmd/guru: adjust describe qualifier function (fix describe test)
The go/types fix for golang/go#44515 changed the type string for unsafe.Pointer from a fixed "unsafe.Pointer" to a customizable package path followed by "Pointer" (the customization was in place for any other object already). The package path customization is done through a user-provider types.Qualifier function. If none is provided, the ordinary package path is used ("unsafe"). Guru provides a package-relative qualifier which leaves away the package path if an object is local to a package. As a result, unsafe.Pointer is printed as "Pointer" which breaks an existing test. Provide no qualifier function when printing a type from package unsafe instead (there's only unsafe.Pointer). Since no qualifier was used in the past, this Guru-specific change will also work when run using earlier Go versions. Fixes golang/go#44596. Updates golang/go#44515. Change-Id: I3c467e4ed09aa13deb50368fe98e42c723a6376b Reviewed-on: https://go-review.googlesource.com/c/tools/+/296289 Trust: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 0150491 commit 24aca17

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/guru/describe.go

+16
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,22 @@ func formatMember(obj types.Object, maxname int) string {
738738
}
739739
}
740740
if typestr == "" {
741+
// The fix for #44515 changed the printing of unsafe.Pointer
742+
// such that it uses a qualifier if one is provided. Using
743+
// the types.RelativeTo qualifier provided here, the output
744+
// is just "Pointer" rather than "unsafe.Pointer". This is
745+
// consistent with the printing of non-type objects but it
746+
// breaks an existing test which needs to work with older
747+
// versions of Go. Re-establish the original output by not
748+
// using a qualifier at all if we're printing a type from
749+
// package unsafe - there's only unsafe.Pointer (#44596).
750+
// NOTE: This correction can be removed (and the test's
751+
// golden file adjusted) once we only run against go1.17
752+
// or bigger.
753+
qualifier := qualifier
754+
if obj.Pkg() == types.Unsafe {
755+
qualifier = nil
756+
}
741757
typestr = types.TypeString(typ, qualifier)
742758
}
743759
buf.WriteString(typestr)

0 commit comments

Comments
 (0)