mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
cmd/gc: print x++ (not x += 1) in errors about x++
Fixes #8311. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews, r https://golang.org/cl/146270043
This commit is contained in:
parent
53c66543e0
commit
52e9bcafe1
|
@ -810,6 +810,13 @@ stmtfmt(Fmt *f, Node *n)
|
|||
break;
|
||||
|
||||
case OASOP:
|
||||
if(n->implicit) {
|
||||
if(n->etype == OADD)
|
||||
fmtprint(f, "%N++", n->left);
|
||||
else
|
||||
fmtprint(f, "%N--", n->left);
|
||||
break;
|
||||
}
|
||||
fmtprint(f, "%N %#O= %N", n->left, n->etype, n->right);
|
||||
break;
|
||||
|
||||
|
|
|
@ -460,11 +460,13 @@ simple_stmt:
|
|||
| expr LINC
|
||||
{
|
||||
$$ = nod(OASOP, $1, nodintconst(1));
|
||||
$$->implicit = 1;
|
||||
$$->etype = OADD;
|
||||
}
|
||||
| expr LDEC
|
||||
{
|
||||
$$ = nod(OASOP, $1, nodintconst(1));
|
||||
$$->implicit = 1;
|
||||
$$->etype = OSUB;
|
||||
}
|
||||
|
||||
|
|
|
@ -600,6 +600,10 @@ reswitch:
|
|||
}
|
||||
if(t->etype != TIDEAL && !eqtype(l->type, r->type)) {
|
||||
defaultlit2(&l, &r, 1);
|
||||
if(n->op == OASOP && n->implicit) {
|
||||
yyerror("invalid operation: %N (non-numeric type %T)", n, l->type);
|
||||
goto error;
|
||||
}
|
||||
yyerror("invalid operation: %N (mismatched types %T and %T)", n, l->type, r->type);
|
||||
goto error;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
16
test/fixedbugs/issue8311.go
Normal file
16
test/fixedbugs/issue8311.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// errorcheck
|
||||
|
||||
// Copyright 2014 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// issue 8311.
|
||||
// error for x++ should say x++ not x += 1
|
||||
|
||||
package p
|
||||
|
||||
func f() {
|
||||
var x []byte
|
||||
x++ // ERROR "invalid operation: x[+][+]"
|
||||
|
||||
}
|
Loading…
Reference in a new issue