Commit fe762b64 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile/internal/gc: better error message for parenthesized go/defer exprs

Change-Id: Ie24d56422ae2196198a6c306716fa867c1442d6e
Reviewed-on: https://go-review.googlesource.com/17043Reviewed-by: default avatarChris Manghane <cmang@golang.org>
parent 5500d469
...@@ -1391,13 +1391,18 @@ func (p *parser) pseudocall() *Node { ...@@ -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 { ...@@ -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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment