Passes toolstash -cmp.
Change-Id: Ib0b6ebf5751ffce2c9500dc67d78e54937ead208
Reviewed-on: https://go-review.googlesource.com/c/go/+/279449
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
var ks []hole
for _, cas := range n.Cases { // cases
if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil {
- cv := cas.Var.(*ir.Name)
+ cv := cas.Var
k := e.dcl(cv) // type switch variables have no ODCL.
if cv.Type().HasPointers() {
ks = append(ks, k.dotType(cv.Type(), cas, "switch case"))
func (n *CaseClause) doChildren(do func(Node) error) error {
var err error
err = maybeDoList(n.init, err, do)
- err = maybeDo(n.Var, err, do)
+ if n.Var != nil {
+ err = maybeDo(n.Var, err, do)
+ }
err = maybeDoList(n.List, err, do)
err = maybeDoList(n.Body, err, do)
return err
}
func (n *CaseClause) editChildren(edit func(Node) Node) {
editList(n.init, edit)
- n.Var = maybeEdit(n.Var, edit)
+ if n.Var != nil {
+ n.Var = edit(n.Var).(*Name)
+ }
editList(n.List, edit)
editList(n.Body, edit)
}
// A CaseClause is a case statement in a switch or select: case List: Body.
type CaseClause struct {
miniStmt
- Var Node // declared variable for this case in type switch
+ Var *Name // declared variable for this case in type switch
List Nodes // list of expressions for switch, early select
Body Nodes
}
w.pos(cas.Pos())
w.stmtList(cas.List)
if namedTypeSwitch {
- w.localName(cas.Var.(*ir.Name))
+ w.localName(cas.Var)
}
w.stmtList(cas.Body)
}
nvar := ncase.Var
nvar.SetType(vt)
if vt != nil {
- nvar = AssignExpr(nvar)
+ nvar = AssignExpr(nvar).(*ir.Name)
} else {
// Clause variable is broken; prevent typechecking.
nvar.SetTypecheck(1)
body ir.Nodes
}
-func (s *typeSwitch) Add(pos src.XPos, typ *types.Type, caseVar, jmp ir.Node) {
+func (s *typeSwitch) Add(pos src.XPos, typ *types.Type, caseVar *ir.Name, jmp ir.Node) {
var body ir.Nodes
if caseVar != nil {
l := []ir.Node{
typecheck.Stmts(l)
body.Append(l...)
} else {
- caseVar = ir.BlankNode
+ caseVar = ir.BlankNode.(*ir.Name)
}
// cv, ok = iface.(type)