1
0
mirror of https://github.com/golang/go synced 2024-09-24 03:10:16 -06:00

cmd/compile/internal/types2: avoid follow-on errors for invalid [...] array

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>
This commit is contained in:
Robert Griesemer 2021-04-20 10:55:59 -07:00
parent 617a83ec68
commit 48b368b01f
3 changed files with 13 additions and 2 deletions

View 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₁)`},

View File

@ -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")

View 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)