From f54303d6cb4e8139ec008d32a59f10a74803afea Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 10 Oct 2013 10:46:54 -0700 Subject: [PATCH] to.tools/go/types: check invalid use of ... with built-ins R=adonovan CC=golang-dev https://golang.org/cl/14531047 --- go/types/builtins.go | 8 ++++- go/types/testdata/builtins.src | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/go/types/builtins.go b/go/types/builtins.go index f06e22e6650..4ffafe3a0e8 100644 --- a/go/types/builtins.go +++ b/go/types/builtins.go @@ -37,8 +37,14 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b // arguments requires special handling } - // check argument count + // append is the only built-in that permits the use of ... for the last argument bin := predeclaredFuncs[id] + if call.Ellipsis.IsValid() && id != _Append { + check.invalidOp(call.Ellipsis, "invalid use of ... with built-in %s", bin.name) + return + } + + // check argument count { msg := "" if nargs < bin.nargs { diff --git a/go/types/testdata/builtins.src b/go/types/testdata/builtins.src index 0abac1ac980..ce75d0ed5bd 100644 --- a/go/types/testdata/builtins.src +++ b/go/types/testdata/builtins.src @@ -96,6 +96,10 @@ func cap1() { // issue 4744 type T struct{ a [10]int } const _ = cap(((*T)(nil)).a) + + var s [][]byte + _ = cap(s) + _ = cap(s... /* ERROR invalid use of \.\.\. */ ) } func cap2() { @@ -117,6 +121,9 @@ func close1() { close(r /* ERROR receive-only channel */) close(c) _ = close /* ERROR used as value */ (c) + + var s []chan int + close(s... /* ERROR invalid use of \.\.\. */ ) } func close2() { @@ -177,6 +184,9 @@ func complex1() { _ = complex(1 /* ERROR integer */ <