]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/types2: report error for invalid type expression
authorRobert Griesemer <gri@golang.org>
Fri, 11 Dec 2020 02:07:09 +0000 (18:07 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 14 Dec 2020 21:29:46 +0000 (21:29 +0000)
This bug was introduced by the change from go/ast to syntax which
represents pointer types as (unary) operations rather than dedicated
StarExpr nodes. Accordingly, this bug does not exist for go/types.
It's still ok to backport the test.

Fixes #43125.

Change-Id: Ic55d913f8afc92862856e1eb7c2861d07fc56cfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/278013
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/types2/fixedbugs/issue43125.src [new file with mode: 0644]
src/cmd/compile/internal/types2/typexpr.go

diff --git a/src/cmd/compile/internal/types2/fixedbugs/issue43125.src b/src/cmd/compile/internal/types2/fixedbugs/issue43125.src
new file mode 100644 (file)
index 0000000..c2bd970
--- /dev/null
@@ -0,0 +1,8 @@
+// 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 _ = new(- /* ERROR not a type */ 1)
+var _ = new(1 /* ERROR not a type */ + 1)
index 22df01b3bea2f367297decba3e259fcc47cecce4..4231577a4f4bd8ced1e0dcafab01f57fb49166e9 100644 (file)
@@ -535,6 +535,9 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) {
                        return typ
                }
 
+               check.errorf(e0, "%s is not a type", e0)
+               check.use(e0)
+
        case *syntax.FuncType:
                typ := new(Signature)
                def.setUnderlying(typ)