]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: added test case for Checker.CheckExpr
authorRobert Griesemer <gri@golang.org>
Mon, 26 Feb 2024 21:26:39 +0000 (13:26 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 27 Feb 2024 17:06:29 +0000 (17:06 +0000)
For #65898.

Change-Id: I495e53060ac56b88a551ccd9901f25bbce97c714
Reviewed-on: https://go-review.googlesource.com/c/go/+/567215
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/go/types/eval_test.go

index dd9bd7f426d0115333ec5f0abf120a391625dc85..1521f2fe41915a1c393709fd04177f08ffe5c924 100644 (file)
@@ -12,6 +12,7 @@ import (
        "go/importer"
        "go/parser"
        "go/token"
+       "go/types"
        "internal/testenv"
        "strings"
        "testing"
@@ -295,3 +296,32 @@ func f(a int, s string) S {
                }
        }
 }
+
+func TestIssue65898(t *testing.T) {
+       const src = `
+package p
+func _[A any](A) {}
+`
+
+       fset := token.NewFileSet()
+       f := mustParse(fset, src)
+
+       var conf types.Config
+       pkg, err := conf.Check(pkgName(src), fset, []*ast.File{f}, nil)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       for _, d := range f.Decls {
+               if fun, _ := d.(*ast.FuncDecl); fun != nil {
+                       // type parameter A is not found at the start of the function type
+                       if err := types.CheckExpr(fset, pkg, fun.Type.Pos(), fun.Type, nil); err == nil || !strings.Contains(err.Error(), "undefined") {
+                               t.Fatalf("got %s, want undefined error", err)
+                       }
+                       // type parameter A must be found at the end of the function type
+                       if err := types.CheckExpr(fset, pkg, fun.Type.End(), fun.Type, nil); err != nil {
+                               t.Fatal(err)
+                       }
+               }
+       }
+}