From ee2f5fafd88b5ce1404fa40e3645a409e9630897 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 13 Feb 2017 09:22:46 -0800 Subject: [PATCH] cmd/compile/internal/parser: don't crash after unexpected token Added missing nil-check. We will get rid of the gcCompat corrections shortly but it's still worthwhile having the new test case added. Fixes #19056. Change-Id: I35bd938a4d789058da15724e34c05e5e631ecad0 Reviewed-on: https://go-review.googlesource.com/36908 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/syntax/parser.go | 2 +- test/fixedbugs/issue19056.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue19056.go diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index a11be9717c7..79d6c8c14dd 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -799,7 +799,7 @@ loop: p.syntax_error("expecting name or (") p.advance(_Semi, _Rparen) } - if gcCompat { + if gcCompat && x != nil { x.init(p) } diff --git a/test/fixedbugs/issue19056.go b/test/fixedbugs/issue19056.go new file mode 100644 index 00000000000..e4e8d07905a --- /dev/null +++ b/test/fixedbugs/issue19056.go @@ -0,0 +1,9 @@ +// 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. + +package p + +var _ = ... . // ERROR "unexpected ..."