]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: report invalid ... in conversions
authorRob Findley <rfindley@google.com>
Fri, 11 Dec 2020 21:24:26 +0000 (16:24 -0500)
committerRobert Findley <rfindley@google.com>
Mon, 14 Dec 2020 22:05:52 +0000 (22:05 +0000)
This is a port of CL 277072 from the dev.typeparams branch.

Fixes #43124

Change-Id: I1424c396dc1ea984ec85b8f31a4d43353bf7e4fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/277352
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/call.go
src/go/types/fixedbugs/issue43124.src [new file with mode: 0644]

index 992598d08ce578656c6a1ce3b188b8be1f30d1fd..6765b17bf340535f91f017a64fdf02caebebea84 100644 (file)
@@ -33,6 +33,10 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind {
                case 1:
                        check.expr(x, e.Args[0])
                        if x.mode != invalid {
+                               if e.Ellipsis.IsValid() {
+                                       check.errorf(e.Args[0], _BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
+                                       break
+                               }
                                check.conversion(x, T)
                        }
                default:
diff --git a/src/go/types/fixedbugs/issue43124.src b/src/go/types/fixedbugs/issue43124.src
new file mode 100644 (file)
index 0000000..f429f74
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+var _ = int(0 /* ERROR invalid use of \.\.\. in conversion to int */ ...)
+
+// test case from issue
+
+type M []string
+
+var (
+       x = []string{"a", "b"}
+       _ = M(x /* ERROR invalid use of \.\.\. in conversion to M */ ...)
+)