diff options
| author | Robert Griesemer <gri@golang.org> | 2023-10-30 17:00:07 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-10-31 16:12:41 +0000 |
| commit | b7a66be69c5857105c4b357d87bb76da87b1dbed (patch) | |
| tree | dc9ea36ea29688f73a341657f463a896e1d9304a /src/cmd/compile/internal/syntax | |
| parent | 25a59decd58d67edb1f0d15c899ecb27c7ebb3d3 (diff) | |
| download | go-b7a66be69c5857105c4b357d87bb76da87b1dbed.tar.xz | |
cmd/compile/internal/syntax: set up dummy name and type if func name is missing
We do the same elsewhere (e.g. in parser.name when a name is missing).
This ensures functions have a (dummy) name and a non-nil type.
Avoids a crash in the type-checker (verified manually).
A test was added here (rather than the type checker) because type-
checker tests are shared between types2 and go/types and error
recovery in this case is different.
Fixes #63835.
Change-Id: I1460fc88d23d80b8d8c181c774d6b0a56ca06317
Reviewed-on: https://go-review.googlesource.com/c/go/+/538059
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax')
| -rw-r--r-- | src/cmd/compile/internal/syntax/parser.go | 3 | ||||
| -rw-r--r-- | src/cmd/compile/internal/syntax/testdata/issue63835.go | 9 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index 913a2f164c..3895f53cf7 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -798,6 +798,9 @@ func (p *parser) funcDeclOrNil() *FuncDecl { f.Name = p.name() f.TParamList, f.Type = p.funcType(context) } else { + f.Name = NewName(p.pos(), "_") + f.Type = new(FuncType) + f.Type.pos = p.pos() msg := "expected name or (" if context != "" { msg = "expected name" diff --git a/src/cmd/compile/internal/syntax/testdata/issue63835.go b/src/cmd/compile/internal/syntax/testdata/issue63835.go new file mode 100644 index 0000000000..3d165c016e --- /dev/null +++ b/src/cmd/compile/internal/syntax/testdata/issue63835.go @@ -0,0 +1,9 @@ +// Copyright 2023 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 + +func (x string) /* ERROR syntax error: unexpected \[, expected name */ []byte { + return []byte(x) +} |
