mirror of
https://github.com/golang/go
synced 2024-09-18 15:32:18 +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")()
|
defer p.trace("pseudocall")()
|
||||||
}
|
}
|
||||||
|
|
||||||
// The expression in go/defer must not be parenthesized;
|
x := p.pexpr(true) // keep_parens so we can report error below
|
||||||
// don't drop ()'s so we can report an error.
|
switch x.Op {
|
||||||
x := p.pexpr(true /* keep_parens */)
|
case OCALL:
|
||||||
if x.Op != OCALL {
|
|
||||||
Yyerror("argument to go/defer must be function call")
|
|
||||||
}
|
|
||||||
return x
|
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 nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// go.y:pexpr (partial)
|
// go.y:pexpr (partial)
|
||||||
|
|
|
@ -19,8 +19,12 @@ type S struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func F() {
|
func F() {
|
||||||
go (F()) // ERROR "must be function call"
|
go F // ERROR "must be function call"
|
||||||
defer (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
|
var s S
|
||||||
(&s.t).F()
|
(&s.t).F()
|
||||||
go (&s.t).F()
|
go (&s.t).F()
|
||||||
|
|
Loading…
Reference in a new issue