Comparable(T1)
Comparable(T2)
}
+
+func TestIssue44515(t *testing.T) {
+ typ := Unsafe.Scope().Lookup("Pointer").Type()
+
+ got := TypeString(typ, nil)
+ want := "unsafe.Pointer"
+ if got != want {
+ t.Errorf("got %q; want %q", got, want)
+ }
+
+ qf := func(pkg *Package) string {
+ if pkg == Unsafe {
+ return "foo"
+ }
+ return ""
+ }
+ got = TypeString(typ, qf)
+ want = "foo.Pointer"
+ if got != want {
+ t.Errorf("got %q; want %q", got, want)
+ }
+}
buf.WriteString("<nil>")
case *Basic:
- if t.kind == UnsafePointer {
- buf.WriteString("unsafe.")
+ // exported basic types go into package unsafe
+ // (currently this is just unsafe.Pointer)
+ if isExported(t.name) {
+ if obj, _ := Unsafe.scope.Lookup(t.name).(*TypeName); obj != nil {
+ writeTypeName(buf, obj, qf)
+ break
+ }
}
+
if gcCompatibilityMode {
// forget the alias names
switch t.kind {
Comparable(T1)
Comparable(T2)
}
+
+func TestIssue44515(t *testing.T) {
+ typ := Unsafe.Scope().Lookup("Pointer").Type()
+
+ got := TypeString(typ, nil)
+ want := "unsafe.Pointer"
+ if got != want {
+ t.Errorf("got %q; want %q", got, want)
+ }
+
+ qf := func(pkg *Package) string {
+ if pkg == Unsafe {
+ return "foo"
+ }
+ return ""
+ }
+ got = TypeString(typ, qf)
+ want = "foo.Pointer"
+ if got != want {
+ t.Errorf("got %q; want %q", got, want)
+ }
+}
import (
"bytes"
"fmt"
+ "go/token"
"unicode/utf8"
)
buf.WriteString("<nil>")
case *Basic:
- if t.kind == UnsafePointer {
- buf.WriteString("unsafe.")
+ // exported basic types go into package unsafe
+ // (currently this is just unsafe.Pointer)
+ if token.IsExported(t.name) {
+ if obj, _ := Unsafe.scope.Lookup(t.name).(*TypeName); obj != nil {
+ writeTypeName(buf, obj, qf)
+ break
+ }
}
+
if gcCompatibilityMode {
// forget the alias names
switch t.kind {