From 5a8435d701c1c8c39f403942d4f6a0ac065635db Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Thu, 29 Apr 2021 11:42:35 -0400 Subject: [PATCH] go/types: add additional test data from types2 Add some test data files that were not included in go/types. - Issue 43125 only pertained to types2 because go/ast differentiates StarExpr, UnaryExpr, and BinaryExpr, so typexpr.go was already catching the invalid type expressions. - Issues 42987 and 43190 are handled differently by go/parser. - main.go2 was not added when ported to go/types, because this work happened on the dev.regabi branch, which didn't support generics. Test files are modified to adjust errors messages and positions, and to update the copyright year. Change-Id: Ia737eaab9afb2b59600b661ccf3eec3cbbb2d66c Reviewed-on: https://go-review.googlesource.com/c/go/+/315070 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/go/types/testdata/check/main.go2 | 7 ++++++ .../types/testdata/fixedbugs/issue42987.src | 10 +++++++++ .../types/testdata/fixedbugs/issue43125.src | 8 +++++++ .../types/testdata/fixedbugs/issue43190.src | 22 +++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 src/go/types/testdata/check/main.go2 create mode 100644 src/go/types/testdata/fixedbugs/issue42987.src create mode 100644 src/go/types/testdata/fixedbugs/issue43125.src create mode 100644 src/go/types/testdata/fixedbugs/issue43190.src diff --git a/src/go/types/testdata/check/main.go2 b/src/go/types/testdata/check/main.go2 new file mode 100644 index 00000000000..65e9aa29629 --- /dev/null +++ b/src/go/types/testdata/check/main.go2 @@ -0,0 +1,7 @@ +// 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. + +package main + +func main[ /* ERROR "func main must have no type parameters" */ T any]() {} diff --git a/src/go/types/testdata/fixedbugs/issue42987.src b/src/go/types/testdata/fixedbugs/issue42987.src new file mode 100644 index 00000000000..6060ec84bde --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue42987.src @@ -0,0 +1,10 @@ +// 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 +// TODO(rFindley) This is a parser error, but in types2 it is a type checking +// error. We could probably do without this check in the parser. +var _ = [... /* ERROR expected array length, found '...' */ ]byte("foo") diff --git a/src/go/types/testdata/fixedbugs/issue43125.src b/src/go/types/testdata/fixedbugs/issue43125.src new file mode 100644 index 00000000000..456888de6b4 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue43125.src @@ -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. + +package p + +var _ = new(- /* ERROR not a type */ 1) +var _ = new(1 /* ERROR not a type */ + 1) diff --git a/src/go/types/testdata/fixedbugs/issue43190.src b/src/go/types/testdata/fixedbugs/issue43190.src new file mode 100644 index 00000000000..96acb3a2e32 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue43190.src @@ -0,0 +1,22 @@ +// 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. + +// Most of the errors below are actually produced by the parser, but we check +// them here for consistency with the types2 tests. + +package p + +import ; /* ERROR invalid import path */ /* ERROR expected 'STRING' */ +import // ERROR expected ';' +var _ int +import /* ERROR expected declaration */ .; + +import () +import (.) +import ( + "fmt" + . +) + +var _ = fmt /* ERROR "undeclared name" */ .Println