Change-Id: Ie24d56422ae2196198a6c306716fa867c1442d6e
Reviewed-on: https://go-review.googlesource.com/17043
Reviewed-by: Chris Manghane <cmang@golang.org>
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)
}
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()