@@ -54,7 +54,6 @@ type caseClauses struct {
54
54
55
55
// typecheckswitch typechecks a switch statement.
56
56
func typecheckswitch (n * Node ) {
57
- lno := lineno
58
57
typecheckslice (n .Ninit .Slice (), Etop )
59
58
60
59
var nilonly string
@@ -67,7 +66,7 @@ func typecheckswitch(n *Node) {
67
66
n .Left .Right = typecheck (n .Left .Right , Erv )
68
67
t = n .Left .Right .Type
69
68
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 )
71
70
}
72
71
} else {
73
72
// expression switch
@@ -82,14 +81,14 @@ func typecheckswitch(n *Node) {
82
81
if t != nil {
83
82
switch {
84
83
case ! okforeq [t .Etype ]:
85
- yyerror ( "cannot switch on %L" , n .Left )
84
+ yyerrorl ( n . Pos , "cannot switch on %L" , n .Left )
86
85
case t .IsSlice ():
87
86
nilonly = "slice"
88
87
case t .IsArray () && ! t .IsComparable ():
89
- yyerror ( "cannot switch on %L" , n .Left )
88
+ yyerrorl ( n . Pos , "cannot switch on %L" , n .Left )
90
89
case t .IsStruct ():
91
90
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 )
93
92
}
94
93
case t .Etype == TFUNC :
95
94
nilonly = "func"
@@ -103,12 +102,11 @@ func typecheckswitch(n *Node) {
103
102
104
103
var def , niltype * Node
105
104
for _ , ncase := range n .List .Slice () {
106
- setlineno (n )
107
105
if ncase .List .Len () == 0 {
108
106
// default
109
107
if def != nil {
110
108
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 ())
112
110
} else {
113
111
def = ncase
114
112
}
@@ -121,6 +119,7 @@ func typecheckswitch(n *Node) {
121
119
if n1 .Type == nil || t == nil {
122
120
continue
123
121
}
122
+
124
123
setlineno (ncase )
125
124
switch top {
126
125
// expression switch
@@ -129,17 +128,17 @@ func typecheckswitch(n *Node) {
129
128
n1 = ls [i1 ]
130
129
switch {
131
130
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 )
133
132
case n1 .Type != nil && assignop (n1 .Type , t , nil ) == 0 && assignop (t , n1 .Type , nil ) == 0 :
134
133
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 )
136
135
} 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 )
138
137
}
139
138
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 )
141
140
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 )
143
142
}
144
143
145
144
// type switch
@@ -150,25 +149,25 @@ func typecheckswitch(n *Node) {
150
149
case n1 .Op == OLITERAL && n1 .Type .IsKind (TNIL ):
151
150
// case nil:
152
151
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 ())
154
153
} else {
155
154
niltype = ncase
156
155
}
157
156
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 )
159
158
// reset to original type
160
159
n1 = n .Left .Right
161
160
ls [i1 ] = n1
162
161
case ! n1 .Type .IsInterface () && t .IsInterface () && ! implements (n1 .Type , t , & missing , & have , & ptr ):
163
162
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" +
165
164
" (wrong type for %v method)\n \t have %v%S\n \t want %v%S" , n .Left .Right , n1 .Type , missing .Sym , have .Sym , have .Type , missing .Sym , missing .Type )
166
165
} else if ! missing .Broke () {
167
166
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" +
169
168
" (%v method has pointer receiver)" , n .Left .Right , n1 .Type , missing .Sym )
170
169
} 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" +
172
171
" (missing %v method)" , n .Left .Right , n1 .Type , missing .Sym )
173
172
}
174
173
}
@@ -196,8 +195,6 @@ func typecheckswitch(n *Node) {
196
195
197
196
typecheckslice (ncase .Nbody .Slice (), Etop )
198
197
}
199
-
200
- lineno = lno
201
198
}
202
199
203
200
// walkswitch walks a switch statement.
0 commit comments