]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't crash when reporting some syntax errors
authorRobert Griesemer <gri@golang.org>
Thu, 23 Mar 2017 03:50:32 +0000 (20:50 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 23 Mar 2017 04:54:27 +0000 (04:54 +0000)
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>
src/cmd/compile/internal/syntax/printer.go
test/fixedbugs/issue19667.go [new file with mode: 0644]

index 426921199eb200304b8cf1c70ad70746132d0b50..64ed0e662c89df5861682b7038d1d9fca7498eff 100644 (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
diff --git a/test/fixedbugs/issue19667.go b/test/fixedbugs/issue19667.go
new file mode 100644 (file)
index 0000000..c94a11d
--- /dev/null
@@ -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"