aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/syntax')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go27
-rw-r--r--src/cmd/compile/internal/syntax/testdata/issue69506.go9
-rw-r--r--src/cmd/compile/internal/syntax/testdata/tparams.go2
3 files changed, 26 insertions, 12 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)
}
diff --git a/src/cmd/compile/internal/syntax/testdata/issue69506.go b/src/cmd/compile/internal/syntax/testdata/issue69506.go
new file mode 100644
index 0000000000..36e9da77c1
--- /dev/null
+++ b/src/cmd/compile/internal/syntax/testdata/issue69506.go
@@ -0,0 +1,9 @@
+// Copyright 2024 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 _(a int, b /* ERROR missing parameter type */ )
+func _(a int, /* ERROR missing parameter name */ []int)
+func _(a int, /* ERROR missing parameter name */ []int, c int)
diff --git a/src/cmd/compile/internal/syntax/testdata/tparams.go b/src/cmd/compile/internal/syntax/testdata/tparams.go
index 4b68a1585f..a4967bf70f 100644
--- a/src/cmd/compile/internal/syntax/testdata/tparams.go
+++ b/src/cmd/compile/internal/syntax/testdata/tparams.go
@@ -13,7 +13,7 @@ type t struct {
}
type t interface {
t[a]
- m /* ERROR method must have no type parameters */ [_ _, /* ERROR mixed */ _]()
+ m /* ERROR method must have no type parameters */ [_ _, _ /* ERROR missing parameter type */ ]()
t[a, b]
}