From 3f9360345cc1e3286abbb7bf5fbce50481a0bbbd Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 4 Jul 2024 00:17:05 +0700 Subject: [PATCH] cmd/compile: prevent un-necessary wrapping in switch statement 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 Reviewed-by: Dmitri Shuralyov Reviewed-by: Keith Randall Reviewed-by: Keith Randall --- src/cmd/compile/internal/noder/writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index 8fed138a4a..c1560941b8 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -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 } -- 2.48.1