Commit 7218b79f authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: match markdcl and popdcl even in case of errors

Change-Id: I22a8a233bc157fa09cd0283fcd4bc14d90faed70
Reviewed-on: https://go-review.googlesource.com/17066Reviewed-by: 's avatarChris Manghane <cmang@golang.org>
parent de2bc572
...@@ -772,7 +772,7 @@ func (p *parser) case_(tswitch *Node) *Node { ...@@ -772,7 +772,7 @@ func (p *parser) case_(tswitch *Node) *Node {
// will be converted to OCASE // will be converted to OCASE
// right will point to next case // right will point to next case
// done in casebody() // done in casebody()
markdcl() markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil) stmt := Nod(OXCASE, nil, nil)
stmt.List = cases stmt.List = cases
if tswitch != nil { if tswitch != nil {
...@@ -798,7 +798,7 @@ func (p *parser) case_(tswitch *Node) *Node { ...@@ -798,7 +798,7 @@ func (p *parser) case_(tswitch *Node) *Node {
// will be converted to OCASE // will be converted to OCASE
// right will point to next case // right will point to next case
// done in casebody() // done in casebody()
markdcl() markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil) stmt := Nod(OXCASE, nil, nil)
var n *Node var n *Node
if cases.Next == nil { if cases.Next == nil {
...@@ -821,7 +821,7 @@ func (p *parser) case_(tswitch *Node) *Node { ...@@ -821,7 +821,7 @@ func (p *parser) case_(tswitch *Node) *Node {
// will be converted to OCASE // will be converted to OCASE
// right will point to next case // right will point to next case
// done in casebody() // done in casebody()
markdcl() markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil) stmt := Nod(OXCASE, nil, nil)
stmt.List = list1(colas(cases, list1(rhs), int32(p.op))) stmt.List = list1(colas(cases, list1(rhs), int32(p.op)))
...@@ -829,16 +829,18 @@ func (p *parser) case_(tswitch *Node) *Node { ...@@ -829,16 +829,18 @@ func (p *parser) case_(tswitch *Node) *Node {
return stmt return stmt
default: default:
markdcl() // for matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil) // don't return nil
p.syntax_error("expecting := or = or : or comma") p.syntax_error("expecting := or = or : or comma")
p.advance(LCASE, LDEFAULT, '}') p.advance(LCASE, LDEFAULT, '}')
return nil return stmt
} }
case LDEFAULT: case LDEFAULT:
// LDEFAULT ':' // LDEFAULT ':'
p.next() p.next()
markdcl() markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil) stmt := Nod(OXCASE, nil, nil)
if tswitch != nil { if tswitch != nil {
if n := tswitch.Left; n != nil { if n := tswitch.Left; n != nil {
...@@ -856,9 +858,11 @@ func (p *parser) case_(tswitch *Node) *Node { ...@@ -856,9 +858,11 @@ func (p *parser) case_(tswitch *Node) *Node {
return stmt return stmt
default: default:
markdcl() // matching popdcl in caseblock
stmt := Nod(OXCASE, nil, nil) // don't return nil
p.syntax_error("expecting case or default or }") p.syntax_error("expecting case or default or }")
p.advance(LCASE, LDEFAULT, '}') p.advance(LCASE, LDEFAULT, '}')
return nil return stmt
} }
} }
...@@ -900,7 +904,7 @@ func (p *parser) caseblock(tswitch *Node) *Node { ...@@ -900,7 +904,7 @@ func (p *parser) caseblock(tswitch *Node) *Node {
defer p.trace("caseblock")() defer p.trace("caseblock")()
} }
stmt := p.case_(tswitch) stmt := p.case_(tswitch) // does markdcl
// If the last token read by the lexer was consumed // If the last token read by the lexer was consumed
// as part of the case, clear it (parser has cleared yychar). // as part of the case, clear it (parser has cleared yychar).
...@@ -1110,7 +1114,7 @@ func (p *parser) if_stmt() *Node { ...@@ -1110,7 +1114,7 @@ func (p *parser) if_stmt() *Node {
stmt.Nbody = p.loop_body("if clause") stmt.Nbody = p.loop_body("if clause")
l := p.elseif_list_else() l := p.elseif_list_else() // does markdcl
n := stmt n := stmt
popdcl() popdcl()
...@@ -1132,7 +1136,7 @@ func (p *parser) elseif() *NodeList { ...@@ -1132,7 +1136,7 @@ func (p *parser) elseif() *NodeList {
} }
// LELSE LIF already consumed // LELSE LIF already consumed
markdcl() markdcl() // matching popdcl in if_stmt
stmt := p.if_header() stmt := p.if_header()
if stmt.Left == nil { if stmt.Left == nil {
......
// errorcheck
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Check various syntax errors with switches.
package main
func _() {
switch {
case 0; // ERROR "expecting := or = or : or comma"
}
switch {
case 0; // ERROR "expecting := or = or : or comma"
default:
}
switch {
if x: // ERROR "expecting case or default or }"
}
}
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