]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: prevent un-necessary wrapping in switch statement
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 3 Jul 2024 17:17:05 +0000 (00:17 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 23 Jul 2024 23:49:48 +0000 (23:49 +0000)
Follow up discussion in CL 594575.

The wrapping in "any" is only necessary if either casType or tagType is
an interface, as "==" in this situation is implemented by upconverting
to an interface anyway.

Change-Id: I73da771d25685a23eec612ac696965c892db4764
Reviewed-on: https://go-review.googlesource.com/c/go/+/596555
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
src/cmd/compile/internal/noder/writer.go

index 8fed138a4a120290daee3525ce9905f98fb75f02..c1560941b8ecec92cde7e00e3fb33c61d97a854b 100644 (file)
@@ -1665,7 +1665,7 @@ func (w *writer) switchStmt(stmt *syntax.SwitchStmt) {
                Outer:
                        for _, clause := range stmt.Body {
                                for _, cas := range syntax.UnpackListExpr(clause.Cases) {
-                                       if casType := w.p.typeOf(cas); !types2.AssignableTo(casType, tagType) {
+                                       if casType := w.p.typeOf(cas); !types2.AssignableTo(casType, tagType) && (types2.IsInterface(casType) || types2.IsInterface(tagType)) {
                                                tagType = types2.NewInterfaceType(nil, nil)
                                                break Outer
                                        }