pos := p.pos()
p.next()
p.xnest++
- x := p.expr() // expr_or_type
+ x := p.expr()
p.xnest--
p.want(_Rparen)
case _Lbrack, _Chan, _Map, _Struct, _Interface:
return p.type_() // othertype
- case _Lbrace:
- // common case: p.header is missing simpleStmt before { in if, for, switch
- p.syntax_error("missing operand")
- // '{' will be consumed in pexpr - no need to consume it here
- return nil
-
default:
p.syntax_error("expecting expression")
p.advance()
// operand may have returned a parenthesized complit
// type; accept it but complain if we have a complit
t := unparen(x)
- // determine if '{' belongs to a complit or a compound_stmt
+ // determine if '{' belongs to a composite literal or a block statement
complit_ok := false
switch t.(type) {
case *Name, *SelectorExpr:
if p.xnest >= 0 {
- // x is considered a comptype
+ // x is considered a composite literal type
complit_ok = true
}
case *ArrayType, *SliceType, *StructType, *MapType:
}
return
}
+ // p.tok != _Lbrace
outer := p.xnest
p.xnest = -1
var condStmt SimpleStmt
var semi struct {
pos src.Pos
- lit string
+ lit string // valid if pos.IsKnown()
}
if p.tok == _Semi {
semi.pos = p.pos()
p.next()
if keyword == _For {
if p.tok != _Semi {
+ if p.tok == _Lbrace {
+ p.syntax_error("expecting for loop condition")
+ goto done
+ }
condStmt = p.simpleStmt(nil, false)
}
p.want(_Semi)
init = nil
}
+done:
// unpack condStmt
switch s := condStmt.(type) {
case nil:
- if keyword == _If {
+ if keyword == _If && semi.pos.IsKnown() {
if semi.lit != "semicolon" {
p.syntax_error_at(semi.pos, fmt.Sprintf("unexpected %s, expecting { after if clause", semi.lit))
} else {
p.xnest++
for p.tok != _EOF && p.tok != _Rparen {
- c.ArgList = append(c.ArgList, p.expr()) // expr_or_type
+ c.ArgList = append(c.ArgList, p.expr())
c.HasDots = p.got(_DotDotDot)
if !p.ocomma(_Rparen) || c.HasDots {
break
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// TODO(mdempsky): Update error expectations for new parser.
-// The new parser emits an extra "missing { after for clause" error.
-// The old parser is supposed to emit this too, but it panics first
-// due to a nil pointer dereference.
-
package main
func main() {
for x // GCCGO_ERROR "undefined"
- { // ERROR "expecting .*{.* after for clause|missing operand"
- z // ERROR "undefined|expecting { after for clause"
+ { // ERROR "unexpected {, expecting for loop condition"
+ z