Skip to content

Commit a568349

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: factor out hasDots to check for ... arguments in calls (cleanup)
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 7731fd9 commit a568349

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

src/cmd/compile/internal/types2/builtins.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
2222

2323
// append is the only built-in that permits the use of ... for the last argument
2424
bin := predeclaredFuncs[id]
25-
if call.HasDots && id != _Append {
25+
if hasDots(call) && id != _Append {
2626
//check.errorf(call.Ellipsis, invalidOp + "invalid use of ... with built-in %s", bin.name)
2727
check.errorf(call,
2828
InvalidDotDotDot,
@@ -114,7 +114,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
114114
// spec: "As a special case, append also accepts a first argument assignable
115115
// to type []byte with a second argument of string type followed by ... .
116116
// This form appends the bytes of the string.
117-
if nargs == 2 && call.HasDots {
117+
if nargs == 2 && hasDots(call) {
118118
if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
119119
y := args[1]
120120
if t := coreString(y.typ); t != nil && isString(t) {

src/cmd/compile/internal/types2/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
209209
break
210210
}
211211
}
212-
if call.HasDots {
212+
if hasDots(call) {
213213
check.errorf(call.ArgList[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
214214
break
215215
}
@@ -468,7 +468,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
468468

469469
nargs := len(args)
470470
npars := sig.params.Len()
471-
ddd := call.HasDots
471+
ddd := hasDots(call)
472472

473473
// set up parameters
474474
sigParams := sig.params // adjusted for variadic functions (may be nil for empty parameter lists!)

src/cmd/compile/internal/types2/util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ import "cmd/compile/internal/syntax"
2020
// If p and q are in different files, p is before q if the filename
2121
// of p sorts lexicographically before the filename of q.
2222
func cmpPos(p, q syntax.Pos) int { return p.Cmp(q) }
23+
24+
// hasDots reports whether the last argument in the call is followed by ...
25+
func hasDots(call *syntax.CallExpr) bool { return call.HasDots }

src/go/types/builtins.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
2222

2323
// append is the only built-in that permits the use of ... for the last argument
2424
bin := predeclaredFuncs[id]
25-
if call.Ellipsis.IsValid() && id != _Append {
25+
if hasDots(call) && id != _Append {
2626
check.errorf(atPos(call.Ellipsis),
2727
InvalidDotDotDot,
2828
invalidOp+"invalid use of ... with built-in %s", bin.name)
@@ -113,7 +113,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
113113
// spec: "As a special case, append also accepts a first argument assignable
114114
// to type []byte with a second argument of string type followed by ... .
115115
// This form appends the bytes of the string.
116-
if nargs == 2 && call.Ellipsis.IsValid() {
116+
if nargs == 2 && hasDots(call) {
117117
if ok, _ := x.assignableTo(check, NewSlice(universeByte), nil); ok {
118118
y := args[1]
119119
if t := coreString(y.typ); t != nil && isString(t) {

src/go/types/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
206206
case 1:
207207
check.expr(nil, x, call.Args[0])
208208
if x.mode != invalid {
209-
if call.Ellipsis.IsValid() {
209+
if hasDots(call) {
210210
check.errorf(call.Args[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
211211
break
212212
}
@@ -471,7 +471,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
471471

472472
nargs := len(args)
473473
npars := sig.params.Len()
474-
ddd := call.Ellipsis.IsValid()
474+
ddd := hasDots(call)
475475

476476
// set up parameters
477477
sigParams := sig.params // adjusted for variadic functions (may be nil for empty parameter lists!)

src/go/types/exprstring.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
105105
WriteExpr(buf, x.Fun)
106106
buf.WriteByte('(')
107107
writeExprList(buf, x.Args)
108-
if x.Ellipsis.IsValid() {
108+
if hasDots(x) {
109109
buf.WriteString("...")
110110
}
111111
buf.WriteByte(')')

src/go/types/util.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
package types
1111

12-
import "go/token"
12+
import (
13+
"go/ast"
14+
"go/token"
15+
)
1316

1417
// cmpPos compares the positions p and q and returns a result r as follows:
1518
//
@@ -20,3 +23,6 @@ import "go/token"
2023
// If p and q are in different files, p is before q if the filename
2124
// of p sorts lexicographically before the filename of q.
2225
func cmpPos(p, q token.Pos) int { return int(p - q) }
26+
27+
// hasDots reports whether the last argument in the call is followed by ...
28+
func hasDots(call *ast.CallExpr) bool { return call.Ellipsis.IsValid() }

0 commit comments

Comments
 (0)