Skip to content

Commit 8a4cee6

Browse files
odeke-emmdempsky
authored andcommitted
cmd/compile: use yyerrorl in typecheckswitch
Replace yyerror usages with yyerrorl in function typecheckswitch. Updates #19683. Change-Id: I7188cdecddd2ce4e06b8cee45b57f3765a979405 Reviewed-on: https://go-review.googlesource.com/38597 Reviewed-by: Josh Bleecher Snyder <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e4e1d08 commit 8a4cee6

File tree

1 file changed

+16
-19
lines changed
  • src/cmd/compile/internal/gc

1 file changed

+16
-19
lines changed

src/cmd/compile/internal/gc/swt.go

+16-19
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type caseClauses struct {
5454

5555
// typecheckswitch typechecks a switch statement.
5656
func typecheckswitch(n *Node) {
57-
lno := lineno
5857
typecheckslice(n.Ninit.Slice(), Etop)
5958

6059
var nilonly string
@@ -67,7 +66,7 @@ func typecheckswitch(n *Node) {
6766
n.Left.Right = typecheck(n.Left.Right, Erv)
6867
t = n.Left.Right.Type
6968
if t != nil && !t.IsInterface() {
70-
yyerror("cannot type switch on non-interface value %L", n.Left.Right)
69+
yyerrorl(n.Pos, "cannot type switch on non-interface value %L", n.Left.Right)
7170
}
7271
} else {
7372
// expression switch
@@ -82,14 +81,14 @@ func typecheckswitch(n *Node) {
8281
if t != nil {
8382
switch {
8483
case !okforeq[t.Etype]:
85-
yyerror("cannot switch on %L", n.Left)
84+
yyerrorl(n.Pos, "cannot switch on %L", n.Left)
8685
case t.IsSlice():
8786
nilonly = "slice"
8887
case t.IsArray() && !t.IsComparable():
89-
yyerror("cannot switch on %L", n.Left)
88+
yyerrorl(n.Pos, "cannot switch on %L", n.Left)
9089
case t.IsStruct():
9190
if f := t.IncomparableField(); f != nil {
92-
yyerror("cannot switch on %L (struct containing %v cannot be compared)", n.Left, f.Type)
91+
yyerrorl(n.Pos, "cannot switch on %L (struct containing %v cannot be compared)", n.Left, f.Type)
9392
}
9493
case t.Etype == TFUNC:
9594
nilonly = "func"
@@ -103,12 +102,11 @@ func typecheckswitch(n *Node) {
103102

104103
var def, niltype *Node
105104
for _, ncase := range n.List.Slice() {
106-
setlineno(n)
107105
if ncase.List.Len() == 0 {
108106
// default
109107
if def != nil {
110108
setlineno(ncase)
111-
yyerror("multiple defaults in switch (first at %v)", def.Line())
109+
yyerrorl(ncase.Pos, "multiple defaults in switch (first at %v)", def.Line())
112110
} else {
113111
def = ncase
114112
}
@@ -121,6 +119,7 @@ func typecheckswitch(n *Node) {
121119
if n1.Type == nil || t == nil {
122120
continue
123121
}
122+
124123
setlineno(ncase)
125124
switch top {
126125
// expression switch
@@ -129,17 +128,17 @@ func typecheckswitch(n *Node) {
129128
n1 = ls[i1]
130129
switch {
131130
case n1.Op == OTYPE:
132-
yyerror("type %v is not an expression", n1.Type)
131+
yyerrorl(ncase.Pos, "type %v is not an expression", n1.Type)
133132
case n1.Type != nil && assignop(n1.Type, t, nil) == 0 && assignop(t, n1.Type, nil) == 0:
134133
if n.Left != nil {
135-
yyerror("invalid case %v in switch on %v (mismatched types %v and %v)", n1, n.Left, n1.Type, t)
134+
yyerrorl(ncase.Pos, "invalid case %v in switch on %v (mismatched types %v and %v)", n1, n.Left, n1.Type, t)
136135
} else {
137-
yyerror("invalid case %v in switch (mismatched types %v and bool)", n1, n1.Type)
136+
yyerrorl(ncase.Pos, "invalid case %v in switch (mismatched types %v and bool)", n1, n1.Type)
138137
}
139138
case nilonly != "" && !isnil(n1):
140-
yyerror("invalid case %v in switch (can only compare %s %v to nil)", n1, nilonly, n.Left)
139+
yyerrorl(ncase.Pos, "invalid case %v in switch (can only compare %s %v to nil)", n1, nilonly, n.Left)
141140
case t.IsInterface() && !n1.Type.IsInterface() && !n1.Type.IsComparable():
142-
yyerror("invalid case %L in switch (incomparable type)", n1)
141+
yyerrorl(ncase.Pos, "invalid case %L in switch (incomparable type)", n1)
143142
}
144143

145144
// type switch
@@ -150,25 +149,25 @@ func typecheckswitch(n *Node) {
150149
case n1.Op == OLITERAL && n1.Type.IsKind(TNIL):
151150
// case nil:
152151
if niltype != nil {
153-
yyerror("multiple nil cases in type switch (first at %v)", niltype.Line())
152+
yyerrorl(ncase.Pos, "multiple nil cases in type switch (first at %v)", niltype.Line())
154153
} else {
155154
niltype = ncase
156155
}
157156
case n1.Op != OTYPE && n1.Type != nil: // should this be ||?
158-
yyerror("%L is not a type", n1)
157+
yyerrorl(ncase.Pos, "%L is not a type", n1)
159158
// reset to original type
160159
n1 = n.Left.Right
161160
ls[i1] = n1
162161
case !n1.Type.IsInterface() && t.IsInterface() && !implements(n1.Type, t, &missing, &have, &ptr):
163162
if have != nil && !missing.Broke() && !have.Broke() {
164-
yyerror("impossible type switch case: %L cannot have dynamic type %v"+
163+
yyerrorl(ncase.Pos, "impossible type switch case: %L cannot have dynamic type %v"+
165164
" (wrong type for %v method)\n\thave %v%S\n\twant %v%S", n.Left.Right, n1.Type, missing.Sym, have.Sym, have.Type, missing.Sym, missing.Type)
166165
} else if !missing.Broke() {
167166
if ptr != 0 {
168-
yyerror("impossible type switch case: %L cannot have dynamic type %v"+
167+
yyerrorl(ncase.Pos, "impossible type switch case: %L cannot have dynamic type %v"+
169168
" (%v method has pointer receiver)", n.Left.Right, n1.Type, missing.Sym)
170169
} else {
171-
yyerror("impossible type switch case: %L cannot have dynamic type %v"+
170+
yyerrorl(ncase.Pos, "impossible type switch case: %L cannot have dynamic type %v"+
172171
" (missing %v method)", n.Left.Right, n1.Type, missing.Sym)
173172
}
174173
}
@@ -196,8 +195,6 @@ func typecheckswitch(n *Node) {
196195

197196
typecheckslice(ncase.Nbody.Slice(), Etop)
198197
}
199-
200-
lineno = lno
201198
}
202199

203200
// walkswitch walks a switch statement.

0 commit comments

Comments
 (0)