"go/importer"
"go/parser"
"go/token"
+ "go/types"
"internal/testenv"
"strings"
"testing"
}
}
}
+
+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)
+ }
+ }
+ }
+}