]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ir: simplify formatting of CompLitExpr
authorMatthew Dempsky <mdempsky@google.com>
Wed, 6 Sep 2023 23:03:38 +0000 (16:03 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 8 Sep 2023 18:54:34 +0000 (18:54 +0000)
Composite literals always have a type now, so the extra fallback code
isn't necessary. But also, to prepare for the upcoming removal of
OrigNode, we need to print OSLICELIT with Implicit set as
"... argument" to satisfy existing regress tests.

Change-Id: I365e879066903eebf1b78e10c1b505565cea3ce3
Reviewed-on: https://go-review.googlesource.com/c/go/+/526396
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ir/fmt.go

index 841b6a2f4f429c9295a8a5e0088fbec8a815de2c..2eed9e467fcd84bca497df9b40a1104136e862ca 100644 (file)
@@ -639,33 +639,17 @@ func exprFmt(n Node, s fmt.State, prec int) {
                }
                fmt.Fprintf(s, "%v { %v }", n.Type(), n.Func.Body)
 
-       case OCOMPLIT:
-               n := n.(*CompLitExpr)
-               if !exportFormat {
-                       if n.Implicit() {
-                               fmt.Fprintf(s, "... argument")
-                               return
-                       }
-                       if typ := n.Type(); typ != nil {
-                               fmt.Fprintf(s, "%v{%s}", typ, ellipsisIf(len(n.List) != 0))
-                               return
-                       }
-                       fmt.Fprint(s, "composite literal")
-                       return
-               }
-               fmt.Fprintf(s, "(%v{ %.v })", n.Type(), n.List)
-
        case OPTRLIT:
                n := n.(*AddrExpr)
                fmt.Fprintf(s, "&%v", n.X)
 
-       case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT:
+       case OCOMPLIT, OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT:
                n := n.(*CompLitExpr)
-               if !exportFormat {
-                       fmt.Fprintf(s, "%v{%s}", n.Type(), ellipsisIf(len(n.List) != 0))
+               if n.Implicit() {
+                       fmt.Fprintf(s, "... argument")
                        return
                }
-               fmt.Fprintf(s, "(%v{ %.v })", n.Type(), n.List)
+               fmt.Fprintf(s, "%v{%s}", n.Type(), ellipsisIf(len(n.List) != 0))
 
        case OKEY:
                n := n.(*KeyExpr)