aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2024-09-30 14:10:40 -0700
committerRobert Griesemer <gri@google.com>2024-09-30 22:04:40 +0000
commitbae2e968e2daadd39c1bdb1221648361d7277ddc (patch)
treea64d9b090a2aa33fad9d008048c6ef7c5091b623 /src/cmd/compile/internal/syntax/parser.go
parent0206eb9679dd3819c44912e6ebdba3b0fbf959a3 (diff)
downloadgo-bae2e968e2daadd39c1bdb1221648361d7277ddc.tar.xz
go/parser, syntax: better error message for parameter missing type
Fixes #69506. Change-Id: I18215e11f214b12d5f65be1d1740181e427f8817 Reviewed-on: https://go-review.googlesource.com/c/go/+/617015 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser.go')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index cd6b6696a2..77abdda867 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -2075,26 +2075,31 @@ func (p *parser) paramList(name *Name, typ Expr, close token, requireNames bool)
}
}
if errPos.IsKnown() {
+ // Not all parameters are named because named != len(list).
+ // If named == typed, there must be parameters that have no types.
+ // They must be at the end of the parameter list, otherwise types
+ // would have been filled in by the right-to-left sweep above and
+ // there would be no error.
+ // If requireNames is set, the parameter list is a type parameter
+ // list.
var msg string
- if requireNames {
- // Not all parameters are named because named != len(list).
- // If named == typed we must have parameters that have no types,
- // and they must be at the end of the parameter list, otherwise
- // the types would have been filled in by the right-to-left sweep
- // above and we wouldn't have an error. Since we are in a type
- // parameter list, the missing types are constraints.
- if named == typed {
- errPos = end // position error at closing ]
+ if named == typed {
+ errPos = end // position error at closing token ) or ]
+ if requireNames {
msg = "missing type constraint"
} else {
+ msg = "missing parameter type"
+ }
+ } else {
+ if requireNames {
msg = "missing type parameter name"
// go.dev/issue/60812
if len(list) == 1 {
msg += " or invalid array length"
}
+ } else {
+ msg = "missing parameter name"
}
- } else {
- msg = "mixed named and unnamed parameters"
}
p.syntaxErrorAt(errPos, msg)
}