diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2020-04-13 23:28:32 -0700 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2020-04-14 17:44:16 +0000 |
| commit | f5439d4c68e14d1f7758ec0e50cc8fe192ad2f5b (patch) | |
| tree | e79cb27f2320fbe97838a54c8fdd1612ffd37ce2 /src | |
| parent | 02ab2c040e20dac433a2a7e1bfca29d3071733ae (diff) | |
| download | go-f5439d4c68e14d1f7758ec0e50cc8fe192ad2f5b.tar.xz | |
cmd/compile: make type switch case positions consistent
CL 228106 moved the position at which we
checked whether a type switch variable had a particular type
from the type switch to the case statement, but only for
single, concrete types. This is a better position,
so this change changes the rest.
Change-Id: I601d4a5c4a0d9400e7804b9f1e729af948349a8f
Reviewed-on: https://go-review.googlesource.com/c/go/+/228220
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/gc/swt.go | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/gc/swt.go b/src/cmd/compile/internal/gc/swt.go index 88c8ea8146..138b0acc53 100644 --- a/src/cmd/compile/internal/gc/swt.go +++ b/src/cmd/compile/internal/gc/swt.go @@ -569,10 +569,10 @@ func walkTypeSwitch(sw *Node) { } if singleType != nil && singleType.IsInterface() { - s.Add(n1.Type, caseVar, jmp) + s.Add(ncase.Pos, n1.Type, caseVar, jmp) caseVarInitialized = true } else { - s.Add(n1.Type, nil, jmp) + s.Add(ncase.Pos, n1.Type, nil, jmp) } } @@ -629,12 +629,12 @@ type typeClause struct { body Nodes } -func (s *typeSwitch) Add(typ *types.Type, caseVar *Node, jmp *Node) { +func (s *typeSwitch) Add(pos src.XPos, typ *types.Type, caseVar, jmp *Node) { var body Nodes if caseVar != nil { l := []*Node{ - nod(ODCL, caseVar, nil), - nod(OAS, caseVar, nil), + nodl(pos, ODCL, caseVar, nil), + nodl(pos, OAS, caseVar, nil), } typecheckslice(l, ctxStmt) body.Append(l...) @@ -643,9 +643,9 @@ func (s *typeSwitch) Add(typ *types.Type, caseVar *Node, jmp *Node) { } // cv, ok = iface.(type) - as := nod(OAS2, nil, nil) + as := nodl(pos, OAS2, nil, nil) as.List.Set2(caseVar, s.okname) // cv, ok = - dot := nod(ODOTTYPE, s.facename, nil) + dot := nodl(pos, ODOTTYPE, s.facename, nil) dot.Type = typ // iface.(type) as.Rlist.Set1(dot) as = typecheck(as, ctxStmt) @@ -653,7 +653,7 @@ func (s *typeSwitch) Add(typ *types.Type, caseVar *Node, jmp *Node) { body.Append(as) // if ok { goto label } - nif := nod(OIF, nil, nil) + nif := nodl(pos, OIF, nil, nil) nif.Left = s.okname nif.Nbody.Set1(jmp) body.Append(nif) |
