diff options
author | smasher164 <aindurti@gmail.com> | 2018-12-04 06:41:39 -0500 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2018-12-05 01:35:59 +0000 |
commit | a7af474359179062a82429da927407d2d5395acc (patch) | |
tree | 0a72552f2653a977fccf5a6ffbfa9f4c491be2f2 /src/cmd/compile | |
parent | be09bdf589a5c25e5d8b68a546e9b84bc1a1977b (diff) | |
download | go-git-a7af474359179062a82429da927407d2d5395acc.tar.gz |
cmd/compile: improve error message for non-final variadic parameter
Previously, when a function signature had defined a non-final variadic
parameter, the error message always referred to the type associated with that
parameter. However, if the offending parameter's name was part of an identifier
list with a variadic type, one could misinterpret the message, thinking the
problem had been with one of the other names in the identifer list.
func bar(a, b ...int) {}
clear ~~~~~~~^ ^~~~~~~~ confusing
This change updates the error message and sets the column position to that of
the offending parameter's name, if it exists.
Fixes #28450.
Change-Id: I076f560925598ed90e218c25d70f9449ffd9b3ea
Reviewed-on: https://go-review.googlesource.com/c/152417
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r-- | src/cmd/compile/internal/gc/noder.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go index 23c9539b0a..89e9ddb668 100644 --- a/src/cmd/compile/internal/gc/noder.go +++ b/src/cmd/compile/internal/gc/noder.go @@ -548,7 +548,11 @@ func (p *noder) param(param *syntax.Field, dddOk, final bool) *Node { if !dddOk { yyerror("cannot use ... in receiver or result parameter list") } else if !final { - yyerror("can only use ... with final parameter in list") + if param.Name == nil { + yyerror("cannot use ... with non-final parameter") + } else { + p.yyerrorpos(param.Name.Pos(), "cannot use ... with non-final parameter %s", param.Name.Value) + } } typ.Op = OTARRAY typ.Right = typ.Left |