This further reduces the differences between go/types and types2.
Change-Id: Ie651c13dd12ecf043b8be92655d48d1ce32d4c5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/562777
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
// append is the only built-in that permits the use of ... for the last argument
bin := predeclaredFuncs[id]
- if call.HasDots && id != _Append {
+ if hasDots(call) && id != _Append {
//check.errorf(call.Ellipsis, invalidOp + "invalid use of ... with built-in %s", bin.name)
check.errorf(call,
InvalidDotDotDot,
// spec: "As a special case, append also accepts a first argument assignable
// to type []byte with a second argument of string type followed by ... .
// This form appends the bytes of the string.
- if nargs == 2 && call.HasDots {
+ if nargs == 2 && hasDots(call) {
if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
y := args[1]
if t := coreString(y.typ); t != nil && isString(t) {
break
}
}
- if call.HasDots {
+ if hasDots(call) {
check.errorf(call.ArgList[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
break
}
nargs := len(args)
npars := sig.params.Len()
- ddd := call.HasDots
+ ddd := hasDots(call)
// set up parameters
sigParams := sig.params // adjusted for variadic functions (may be nil for empty parameter lists!)
// If p and q are in different files, p is before q if the filename
// of p sorts lexicographically before the filename of q.
func cmpPos(p, q syntax.Pos) int { return p.Cmp(q) }
+
+// hasDots reports whether the last argument in the call is followed by ...
+func hasDots(call *syntax.CallExpr) bool { return call.HasDots }
// append is the only built-in that permits the use of ... for the last argument
bin := predeclaredFuncs[id]
- if call.Ellipsis.IsValid() && id != _Append {
+ if hasDots(call) && id != _Append {
check.errorf(atPos(call.Ellipsis),
InvalidDotDotDot,
invalidOp+"invalid use of ... with built-in %s", bin.name)
// spec: "As a special case, append also accepts a first argument assignable
// to type []byte with a second argument of string type followed by ... .
// This form appends the bytes of the string.
- if nargs == 2 && call.Ellipsis.IsValid() {
+ if nargs == 2 && hasDots(call) {
if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
y := args[1]
if t := coreString(y.typ); t != nil && isString(t) {
case 1:
check.expr(nil, x, call.Args[0])
if x.mode != invalid {
- if call.Ellipsis.IsValid() {
+ if hasDots(call) {
check.errorf(call.Args[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
break
}
nargs := len(args)
npars := sig.params.Len()
- ddd := call.Ellipsis.IsValid()
+ ddd := hasDots(call)
// set up parameters
sigParams := sig.params // adjusted for variadic functions (may be nil for empty parameter lists!)
WriteExpr(buf, x.Fun)
buf.WriteByte('(')
writeExprList(buf, x.Args)
- if x.Ellipsis.IsValid() {
+ if hasDots(x) {
buf.WriteString("...")
}
buf.WriteByte(')')
package types
-import "go/token"
+import (
+ "go/ast"
+ "go/token"
+)
// cmpPos compares the positions p and q and returns a result r as follows:
//
// If p and q are in different files, p is before q if the filename
// of p sorts lexicographically before the filename of q.
func cmpPos(p, q token.Pos) int { return int(p - q) }
+
+// hasDots reports whether the last argument in the call is followed by ...
+func hasDots(call *ast.CallExpr) bool { return call.Ellipsis.IsValid() }