From: Matthew Dempsky Date: Wed, 6 Sep 2023 23:03:38 +0000 (-0700) Subject: cmd/compile/internal/ir: simplify formatting of CompLitExpr X-Git-Tag: go1.22rc1~938 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0a49d4a7786dcc77b6ff4d687b6d4b14f307b5ef;p=gostls13.git cmd/compile/internal/ir: simplify formatting of CompLitExpr 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 LUCI-TryBot-Result: Go LUCI Auto-Submit: Matthew Dempsky Reviewed-by: Keith Randall Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ir/fmt.go b/src/cmd/compile/internal/ir/fmt.go index 841b6a2f4f..2eed9e467f 100644 --- a/src/cmd/compile/internal/ir/fmt.go +++ b/src/cmd/compile/internal/ir/fmt.go @@ -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)