Skip to content

Commit e59fd36

Browse files
timothy-kingGo LUCI
authored and
Go LUCI
committed
go/ssa: use ZeroString unconditionally
Follow up to https://go.dev/cl/626537 Change-Id: Ib8dee860c5ca65ea3dab8ef68564f9fe46c74832 Reviewed-on: https://go-review.googlesource.com/c/tools/+/628535 Reviewed-by: Robert Findley <[email protected]> Commit-Queue: Tim King <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 60bc93d commit e59fd36

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

go/callgraph/vta/testdata/src/callgraph_interfaces.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ func Baz(b bool) {
4949

5050
// func Do(b bool) I:
5151
// ...
52-
// t1 = (C).Foo(struct{}{}:C)
52+
// t1 = (C).Foo(C{}:C)
5353
// t2 = NewB()
5454
// t3 = make I <- B (t2)
5555
// return t3
5656

5757
// WANT:
5858
// Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
59-
// Do: (C).Foo(struct{}{}:C) -> C.Foo; NewB() -> NewB
59+
// Do: (C).Foo(C{}:C) -> C.Foo; NewB() -> NewB

go/callgraph/vta/testdata/src/callgraph_static.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func Baz(a A) {
2222
// func Baz(a A):
2323
// t0 = (A).foo(a)
2424
// t1 = Bar()
25-
// t2 = Baz(struct{}{}:A)
25+
// t2 = Baz(A{}:A)
2626

2727
// WANT:
28-
// Baz: (A).foo(a) -> A.foo; Bar() -> Bar; Baz(struct{}{}:A) -> Baz
28+
// Baz: (A).foo(a) -> A.foo; Bar() -> Bar; Baz(A{}:A) -> Baz

go/callgraph/vta/testdata/src/callgraph_type_aliases.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func Baz(b bool) {
5858

5959
// func Do(b bool) I:
6060
// ...
61-
// t1 = (C).Foo(struct{}{}:Z)
61+
// t1 = (C).Foo(Z{}:Z)
6262
// t2 = NewY()
6363
// t3 = make I <- B (t2)
6464
// return t3
6565

6666
// WANT:
6767
// Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
68-
// Do: (C).Foo(struct{}{}:Z) -> C.Foo; NewY() -> NewY
68+
// Do: (C).Foo(Z{}:Z) -> C.Foo; NewY() -> NewY

go/callgraph/vta/vta_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
func TestVTACallGraph(t *testing.T) {
24-
errDiff := func(want, got, missing []string) {
24+
errDiff := func(t *testing.T, want, got, missing []string) {
2525
t.Errorf("got:\n%s\n\nwant:\n%s\n\nmissing:\n%s\n\ndiff:\n%s",
2626
strings.Join(got, "\n"),
2727
strings.Join(want, "\n"),
@@ -60,14 +60,14 @@ func TestVTACallGraph(t *testing.T) {
6060
g := CallGraph(ssautil.AllFunctions(prog), nil)
6161
got := callGraphStr(g)
6262
if missing := setdiff(want, got); len(missing) > 0 {
63-
errDiff(want, got, missing)
63+
errDiff(t, want, got, missing)
6464
}
6565

6666
// Repeat the test with explicit CHA initial call graph.
6767
g = CallGraph(ssautil.AllFunctions(prog), cha.CallGraph(prog))
6868
got = callGraphStr(g)
6969
if missing := setdiff(want, got); len(missing) > 0 {
70-
errDiff(want, got, missing)
70+
errDiff(t, want, got, missing)
7171
}
7272
})
7373
}

go/ssa/const.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,7 @@ func zeroConst(t types.Type) *Const {
7878
func (c *Const) RelString(from *types.Package) string {
7979
var s string
8080
if c.Value == nil {
81-
if _, ok := c.typ.(*types.TypeParam); ok {
82-
// Type parameter's underlying type may be interface that is
83-
// nillable. A better zero value of type parameter is *new(T).
84-
s = typesinternal.ZeroString(c.typ, types.RelativeTo(from))
85-
} else {
86-
s = typesinternal.ZeroString(c.typ.Underlying(), types.RelativeTo(from))
87-
}
81+
s = typesinternal.ZeroString(c.typ, types.RelativeTo(from))
8882
} else if c.Value.Kind() == constant.String {
8983
s = constant.StringVal(c.Value)
9084
const max = 20

0 commit comments

Comments
 (0)