cmd/compile: don't crash when reporting some syntax errors

Fixes #19667.

Change-Id: Iaa71e2020af123c1bd3ac25e0b760956688e8bdf
Reviewed-on: https://go-review.googlesource.com/38458
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2017-03-22 20:50:32 -07:00
parent 2ae79d0711
commit b5e1ae46ad
2 changed files with 16 additions and 0 deletions

View file

@ -341,6 +341,9 @@ func (p *printer) printNode(n Node) {
func (p *printer) printRawNode(n Node) {
switch n := n.(type) {
case nil:
// we should not reach here but don't crash
// expressions and types
case *Name:
p.print(_Name, n.Value) // _Name requires actual value following immediately

View file

@ -0,0 +1,13 @@
// errorcheck
// Copyright 2017 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.
// Make sure we don't crash when reporting this error.
package p
func f() {
if err := http.ListenAndServe(
} // ERROR "unexpected }, expecting expression"