]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: avoid follow-on errors for invalid [...] array
authorRobert Griesemer <gri@golang.org>
Tue, 20 Apr 2021 17:55:59 +0000 (10:55 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 22 Apr 2021 04:04:40 +0000 (04:04 +0000)
Fixes #42987.

Change-Id: Iaaa46e1f79525cd1e418c1a81a6414d11f8120b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/311889
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/fixedbugs/issue42987.src [new file with mode: 0644]
src/cmd/compile/internal/types2/typexpr.go

index 68048f28d3cb0b92dca6a0fba42fdf4088afdc7f..c90f2e7510ecd53918808208ffcb86e27d42e4ae 100644 (file)
@@ -326,7 +326,7 @@ func TestTypesInfo(t *testing.T) {
                {brokenPkg + `x2; func _() { var a, b string; type x struct {f string}; z := &x{f: a, f: b,}}`, `b`, `string`},
                {brokenPkg + `x3; var x = panic("");`, `panic`, `func(interface{})`},
                {`package x4; func _() { panic("") }`, `panic`, `func(interface{})`},
-               {brokenPkg + `x5; func _() { var x map[string][...]int; x = map[string][...]int{"": {1,2,3}} }`, `x`, `map[string][-1]int`},
+               {brokenPkg + `x5; func _() { var x map[string][...]int; x = map[string][...]int{"": {1,2,3}} }`, `x`, `map[string]invalid type`},
 
                // parameterized functions
                {genericPkg + `p0; func f[T any](T); var _ = f[int]`, `f`, `func[T₁ interface{}](T₁)`},
diff --git a/src/cmd/compile/internal/types2/fixedbugs/issue42987.src b/src/cmd/compile/internal/types2/fixedbugs/issue42987.src
new file mode 100644 (file)
index 0000000..8aa3544
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2021 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.
+
+// Check that there is only one error (no follow-on errors).
+
+package p
+var _ = [ /* ERROR invalid use of .* array */ ...]byte("foo")
index 61b290c075109057cd93cdcdf9104dd0806a6e2f..e64d804c30b8ccc59a9c5532d714a624109c0cca 100644 (file)
@@ -518,7 +518,10 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) {
                        typ.len = -1
                }
                typ.elem = check.varType(e.Elem)
-               return typ
+               if typ.len >= 0 {
+                       return typ
+               }
+               // report error if we encountered [...]
 
        case *syntax.SliceType:
                typ := new(Slice)