]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: fix error message for ... without type
authorRobert Griesemer <gri@golang.org>
Wed, 14 Apr 2021 20:10:34 +0000 (13:10 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 15 Apr 2021 19:41:38 +0000 (19:41 +0000)
Only complain about missing type; leave it to type-checking
to decide whether "..." is permitted in the first place.

Fixes #43674.

Change-Id: Icbc8f084e364fe3ac16076406a134354219c08d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/310209
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/testdata/issue43674.src [new file with mode: 0644]
test/fixedbugs/bug228.go

index 026297432dfceaf0c290d2228648d1ec5a0cb064..80250212dd3c1c0fd43ed8dd8b6d172a24832ad6 100644 (file)
@@ -1836,7 +1836,7 @@ func (p *parser) paramDeclOrNil(name *Name) *Field {
                t.Elem = p.typeOrNil()
                if t.Elem == nil {
                        t.Elem = p.badExpr()
-                       p.syntaxError("final argument in variadic function missing type")
+                       p.syntaxError("... is missing type")
                }
                f.Type = t
                return f
diff --git a/src/cmd/compile/internal/syntax/testdata/issue43674.src b/src/cmd/compile/internal/syntax/testdata/issue43674.src
new file mode 100644 (file)
index 0000000..51c692a
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2021 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 _(... /* ERROR [.][.][.] is missing type */ )
+func _(... /* ERROR [.][.][.] is missing type */ , int)
+
+func _(a, b ... /* ERROR [.][.][.] is missing type */ )
+func _(a, b ... /* ERROR [.][.][.] is missing type */ , x int)
+
+func _()(... /* ERROR [.][.][.] is missing type */ )
index f7ac670689bd73c35f006f2fd6e51813dc818bee..50e895917fab26d5e50cdc0ebb10dde58cc98850 100644 (file)
@@ -8,7 +8,7 @@ package main
 
 func f(x int, y ...int)        // ok
 
-func g(x int, y float32) (...) // ERROR "[.][.][.]" "final argument"
+func g(x int, y float32) (...) // ERROR "[.][.][.]"
 
 func h(x, y ...int)            // ERROR "[.][.][.]"