зеркало из https://github.com/golang/tools.git
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 <rfindley@google.com> Commit-Queue: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Родитель
60bc93d368
Коммит
e59fd368eb
|
@ -49,11 +49,11 @@ func Baz(b bool) {
|
|||
|
||||
// func Do(b bool) I:
|
||||
// ...
|
||||
// t1 = (C).Foo(struct{}{}:C)
|
||||
// t1 = (C).Foo(C{}:C)
|
||||
// t2 = NewB()
|
||||
// t3 = make I <- B (t2)
|
||||
// return t3
|
||||
|
||||
// WANT:
|
||||
// Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
|
||||
// Do: (C).Foo(struct{}{}:C) -> C.Foo; NewB() -> NewB
|
||||
// Do: (C).Foo(C{}:C) -> C.Foo; NewB() -> NewB
|
||||
|
|
|
@ -22,7 +22,7 @@ func Baz(a A) {
|
|||
// func Baz(a A):
|
||||
// t0 = (A).foo(a)
|
||||
// t1 = Bar()
|
||||
// t2 = Baz(struct{}{}:A)
|
||||
// t2 = Baz(A{}:A)
|
||||
|
||||
// WANT:
|
||||
// Baz: (A).foo(a) -> A.foo; Bar() -> Bar; Baz(struct{}{}:A) -> Baz
|
||||
// Baz: (A).foo(a) -> A.foo; Bar() -> Bar; Baz(A{}:A) -> Baz
|
||||
|
|
|
@ -58,11 +58,11 @@ func Baz(b bool) {
|
|||
|
||||
// func Do(b bool) I:
|
||||
// ...
|
||||
// t1 = (C).Foo(struct{}{}:Z)
|
||||
// t1 = (C).Foo(Z{}:Z)
|
||||
// t2 = NewY()
|
||||
// t3 = make I <- B (t2)
|
||||
// return t3
|
||||
|
||||
// WANT:
|
||||
// Baz: Do(b) -> Do; invoke t0.Foo() -> A.Foo, B.Foo
|
||||
// Do: (C).Foo(struct{}{}:Z) -> C.Foo; NewY() -> NewY
|
||||
// Do: (C).Foo(Z{}:Z) -> C.Foo; NewY() -> NewY
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
func TestVTACallGraph(t *testing.T) {
|
||||
errDiff := func(want, got, missing []string) {
|
||||
errDiff := func(t *testing.T, want, got, missing []string) {
|
||||
t.Errorf("got:\n%s\n\nwant:\n%s\n\nmissing:\n%s\n\ndiff:\n%s",
|
||||
strings.Join(got, "\n"),
|
||||
strings.Join(want, "\n"),
|
||||
|
@ -60,14 +60,14 @@ func TestVTACallGraph(t *testing.T) {
|
|||
g := CallGraph(ssautil.AllFunctions(prog), nil)
|
||||
got := callGraphStr(g)
|
||||
if missing := setdiff(want, got); len(missing) > 0 {
|
||||
errDiff(want, got, missing)
|
||||
errDiff(t, want, got, missing)
|
||||
}
|
||||
|
||||
// Repeat the test with explicit CHA initial call graph.
|
||||
g = CallGraph(ssautil.AllFunctions(prog), cha.CallGraph(prog))
|
||||
got = callGraphStr(g)
|
||||
if missing := setdiff(want, got); len(missing) > 0 {
|
||||
errDiff(want, got, missing)
|
||||
errDiff(t, want, got, missing)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -78,13 +78,7 @@ func zeroConst(t types.Type) *Const {
|
|||
func (c *Const) RelString(from *types.Package) string {
|
||||
var s string
|
||||
if c.Value == nil {
|
||||
if _, ok := c.typ.(*types.TypeParam); ok {
|
||||
// Type parameter's underlying type may be interface that is
|
||||
// nillable. A better zero value of type parameter is *new(T).
|
||||
s = typesinternal.ZeroString(c.typ, types.RelativeTo(from))
|
||||
} else {
|
||||
s = typesinternal.ZeroString(c.typ.Underlying(), types.RelativeTo(from))
|
||||
}
|
||||
s = typesinternal.ZeroString(c.typ, types.RelativeTo(from))
|
||||
} else if c.Value.Kind() == constant.String {
|
||||
s = constant.StringVal(c.Value)
|
||||
const max = 20
|
||||
|
|
Загрузка…
Ссылка в новой задаче