aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDidier Spezia <didier.06@gmail.com>2015-10-04 20:33:02 +0000
committerRuss Cox <rsc@golang.org>2015-12-07 20:21:21 +0000
commit70da2d0a2a4292cf210f8f8d48129d35ad8c54fb (patch)
tree6f698bfd36d29c15e12e968e9a23743dceb616cc /src
parent715f63778db01260a09ae8caa4fce2ece309c3ae (diff)
downloadgo-70da2d0a2a4292cf210f8f8d48129d35ad8c54fb.tar.xz
cmd/compile/internal/gc: fix internal compiler error on invalid declaration
Following an empty import, a declaration involving a ? symbol generates an internal compiler error when the name of the symbol (in newname function). package a import"" var? go.go:2: import path is empty go.go:3: internal compiler error: newname nil Make sure dclname is not called when the symbol is nil. The error message is now: go.go:2: import path is empty go.go:3: invalid declaration go.go:4: syntax error: unexpected EOF This CL was initially meant to be applied to the old parser, and has been updated to apply to the new parser. Fixes #11610 Change-Id: I75e07622fb3af1d104e3a38c89d9e128e3b94522 Reviewed-on: https://go-review.googlesource.com/15268 Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/parser.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/gc/parser.go b/src/cmd/compile/internal/gc/parser.go
index 3da648a151..16e0802e3e 100644
--- a/src/cmd/compile/internal/gc/parser.go
+++ b/src/cmd/compile/internal/gc/parser.go
@@ -1738,6 +1738,18 @@ func (p *parser) new_name(sym *Sym) *Node {
return nil
}
+func (p *parser) dcl_name(sym *Sym) *Node {
+ if trace && Debug['x'] != 0 {
+ defer p.trace("dcl_name")()
+ }
+
+ if sym == nil {
+ yyerrorl(int(prevlineno), "invalid declaration")
+ return nil
+ }
+ return dclname(sym)
+}
+
func (p *parser) onew_name() *Node {
if trace && Debug['x'] != 0 {
defer p.trace("onew_name")()
@@ -2736,9 +2748,9 @@ func (p *parser) dcl_name_list() *NodeList {
defer p.trace("dcl_name_list")()
}
- l := list1(dclname(p.sym()))
+ l := list1(p.dcl_name(p.sym()))
for p.got(',') {
- l = list(l, dclname(p.sym()))
+ l = list(l, p.dcl_name(p.sym()))
}
return l
}