mirror of
https://github.com/golang/go
synced 2024-11-17 02:14:42 -07:00
go/types: added test case for Checker.CheckExpr
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>
This commit is contained in:
parent
49319ed5c7
commit
98bccd3513
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user