1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:44:41 -07:00

cmd/compile/internal/types2: enable disabled part of an example test (cleanup)

Change-Id: I8ffb198d64ec1b89e6d13bfa299bf699f1ca3830
Reviewed-on: https://go-review.googlesource.com/c/go/+/628156
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2024-11-14 12:19:32 -08:00 committed by Gopher Robot
parent 4003ee79d0
commit c9ac589853

View File

@ -62,7 +62,7 @@ func Unused() { {}; {{ var x int; _ = x }} } // make sure empty block scopes get
// For determinism, we redact addresses.
var buf strings.Builder
pkg.Scope().WriteTo(&buf, 0, true)
rx := regexp.MustCompile(` 0x[a-fA-F0-9]*`)
rx := regexp.MustCompile(` 0x[a-fA-F\d]*`)
fmt.Println(rx.ReplaceAllString(buf.String(), ""))
// Output:
@ -152,24 +152,23 @@ func fib(x int) int {
fmt.Println(strings.Join(items, "\n"))
fmt.Println()
// TODO(gri) Enable once positions are updated/verified
// fmt.Println("Types and Values of each expression:")
// items = nil
// for expr, tv := range info.Types {
// var buf strings.Builder
// posn := expr.Pos()
// tvstr := tv.Type.String()
// if tv.Value != nil {
// tvstr += " = " + tv.Value.String()
// }
// // line:col | expr | mode : type = value
// fmt.Fprintf(&buf, "%2d:%2d | %-19s | %-7s : %s",
// posn.Line(), posn.Col(), types2.ExprString(expr),
// mode(tv), tvstr)
// items = append(items, buf.String())
// }
// slices.Sort(items)
// fmt.Println(strings.Join(items, "\n"))
fmt.Println("Types and Values of each expression:")
items = nil
for expr, tv := range info.Types {
var buf strings.Builder
posn := syntax.StartPos(expr)
tvstr := tv.Type.String()
if tv.Value != nil {
tvstr += " = " + tv.Value.String()
}
// line:col | expr | mode : type = value
fmt.Fprintf(&buf, "%2d:%2d | %-19s | %-7s : %s",
posn.Line(), posn.Col(), types2.ExprString(expr),
mode(tv), tvstr)
items = append(items, buf.String())
}
slices.Sort(items)
fmt.Println(strings.Join(items, "\n"))
// Output:
// InitOrder: [c = "hello" b = S(c) a = len(b)]
@ -199,36 +198,35 @@ func fib(x int) int {
// var x int:
// defined at fib:8:10
// used at 10:10, 12:13, 12:24, 9:5
//
// Types and Values of each expression:
// 4: 8 | string | type : string
// 6:15 | len | builtin : func(fib.S) int
// 6:15 | len(b) | value : int
// 6:19 | b | var : fib.S
// 6:23 | S | type : fib.S
// 6:23 | S(c) | value : fib.S
// 6:25 | c | var : string
// 6:29 | "hello" | value : string = "hello"
// 8:12 | int | type : int
// 8:17 | int | type : int
// 9: 5 | x | var : int
// 9: 5 | x < 2 | value : untyped bool
// 9: 9 | 2 | value : int = 2
// 10:10 | x | var : int
// 12: 9 | fib | value : func(x int) int
// 12: 9 | fib(x - 1) | value : int
// 12: 9 | fib(x - 1) - fib(x - 2) | value : int
// 12:13 | x | var : int
// 12:13 | x - 1 | value : int
// 12:15 | 1 | value : int = 1
// 12:20 | fib | value : func(x int) int
// 12:20 | fib(x - 2) | value : int
// 12:24 | x | var : int
// 12:24 | x - 2 | value : int
// 12:26 | 2 | value : int = 2
}
// TODO(gri) Enable once positions are updated/verified
// Types and Values of each expression:
// 4: 8 | string | type : string
// 6:15 | len | builtin : func(string) int
// 6:15 | len(b) | value : int
// 6:19 | b | var : fib.S
// 6:23 | S | type : fib.S
// 6:23 | S(c) | value : fib.S
// 6:25 | c | var : string
// 6:29 | "hello" | value : string = "hello"
// 8:12 | int | type : int
// 8:17 | int | type : int
// 9: 5 | x | var : int
// 9: 5 | x < 2 | value : untyped bool
// 9: 9 | 2 | value : int = 2
// 10:10 | x | var : int
// 12: 9 | fib | value : func(x int) int
// 12: 9 | fib(x - 1) | value : int
// 12: 9 | fib(x - 1) - fib(x - 2) | value : int
// 12:13 | x | var : int
// 12:13 | x - 1 | value : int
// 12:15 | 1 | value : int = 1
// 12:20 | fib | value : func(x int) int
// 12:20 | fib(x - 2) | value : int
// 12:24 | x | var : int
// 12:24 | x - 2 | value : int
// 12:26 | 2 | value : int = 2
func mode(tv types2.TypeAndValue) string {
switch {
case tv.IsVoid():