mirror of
https://github.com/golang/go
synced 2024-09-15 14:10:17 +00:00
cmd/compile/internal/gc: better error message for parenthesized go/defer exprs
Change-Id: Ie24d56422ae2196198a6c306716fa867c1442d6e Reviewed-on: https://go-review.googlesource.com/17043 Reviewed-by: Chris Manghane <cmang@golang.org>
This commit is contained in:
parent
5500d46914
commit
fe762b6466
|
@ -1391,13 +1391,18 @@ func (p *parser) pseudocall() *Node {
|
|||
defer p.trace("pseudocall")()
|
||||
}
|
||||
|
||||
// The expression in go/defer must not be parenthesized;
|
||||
// don't drop ()'s so we can report an error.
|
||||
x := p.pexpr(true /* keep_parens */)
|
||||
if x.Op != OCALL {
|
||||
Yyerror("argument to go/defer must be function call")
|
||||
x := p.pexpr(true) // keep_parens so we can report error below
|
||||
switch x.Op {
|
||||
case OCALL:
|
||||
return x
|
||||
case OPAREN:
|
||||
Yyerror("expression in go/defer must not be parenthesized")
|
||||
// already progressed, no need to advance
|
||||
default:
|
||||
Yyerror("expression in go/defer must be function call")
|
||||
// already progressed, no need to advance
|
||||
}
|
||||
return x
|
||||
return nil
|
||||
}
|
||||
|
||||
// go.y:pexpr (partial)
|
||||
|
|
|
@ -19,8 +19,12 @@ type S struct {
|
|||
}
|
||||
|
||||
func F() {
|
||||
go (F()) // ERROR "must be function call"
|
||||
defer (F()) // ERROR "must be function call"
|
||||
go F // ERROR "must be function call"
|
||||
defer F // ERROR "must be function call"
|
||||
go (F) // ERROR "must be function call|must not be parenthesized"
|
||||
defer (F) // ERROR "must be function call|must not be parenthesized"
|
||||
go (F()) // ERROR "must be function call|must not be parenthesized"
|
||||
defer (F()) // ERROR "must be function call|must not be parenthesized"
|
||||
var s S
|
||||
(&s.t).F()
|
||||
go (&s.t).F()
|
||||
|
|
Loading…
Reference in a new issue