]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: factor out hasDots to check for ... arguments in calls (cleanup)
authorRobert Griesemer <gri@golang.org>
Thu, 8 Feb 2024 19:14:35 +0000 (11:14 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 8 Feb 2024 19:31:44 +0000 (19:31 +0000)
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>
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/util.go
src/go/types/builtins.go
src/go/types/call.go
src/go/types/exprstring.go
src/go/types/util.go

index e32293a9071901a3d48a35a790694c0c49e11dc8..5db3ae2fa48bae23dfe7d75a2e29cef2b409c071 100644 (file)
@@ -22,7 +22,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        // 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,
@@ -114,7 +114,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                // 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) {
index b8f8a418bb8648b064c145020b413820c5e66e88..7e4cf8974ffcea56d636e81ba2696fc2589f0bfe 100644 (file)
@@ -209,7 +209,7 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {
                                                break
                                        }
                                }
-                               if call.HasDots {
+                               if hasDots(call) {
                                        check.errorf(call.ArgList[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
                                        break
                                }
@@ -468,7 +468,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
 
        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!)
index 01da1c12ca341ad371dc4a3c67544a8dac47179f..d77da478fac1cf9dde00b32e9dac801b719dca46 100644 (file)
@@ -20,3 +20,6 @@ import "cmd/compile/internal/syntax"
 // 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 }
index 325a6d67c5cf2b0e97adf6797b457b84feae7914..b49af554695cc6c32fb90eae384c3eec100eeff2 100644 (file)
@@ -22,7 +22,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        // 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)
@@ -113,7 +113,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                // 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) {
index 2c55c63d1d75dfa893c848b6da757c60cd8b9401..dcd833d23c03c609b9eefe3e06f34d9682deeb1d 100644 (file)
@@ -206,7 +206,7 @@ func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
                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
                                }
@@ -471,7 +471,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
 
        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!)
index 3cdf30fba1a5148499862b77e6d7f288996db75c..0403a06d8c5321e5a39d821b6beb95bfa81b0190 100644 (file)
@@ -105,7 +105,7 @@ func WriteExpr(buf *bytes.Buffer, x ast.Expr) {
                WriteExpr(buf, x.Fun)
                buf.WriteByte('(')
                writeExprList(buf, x.Args)
-               if x.Ellipsis.IsValid() {
+               if hasDots(x) {
                        buf.WriteString("...")
                }
                buf.WriteByte(')')
index 87e1240010bda1e46ff0b56f470ae1fac19f762c..910a0f16d989d9ff488e4db1ee7922cc51433b43 100644 (file)
@@ -9,7 +9,10 @@
 
 package types
 
-import "go/token"
+import (
+       "go/ast"
+       "go/token"
+)
 
 // cmpPos compares the positions p and q and returns a result r as follows:
 //
@@ -20,3 +23,6 @@ import "go/token"
 // 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() }