Skip to content

Commit 98bccd3

Browse files
griesemergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
1 parent 49319ed commit 98bccd3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/go/types/eval_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go/importer"
1313
"go/parser"
1414
"go/token"
15+
"go/types"
1516
"internal/testenv"
1617
"strings"
1718
"testing"
@@ -295,3 +296,32 @@ func f(a int, s string) S {
295296
}
296297
}
297298
}
299+
300+
func TestIssue65898(t *testing.T) {
301+
const src = `
302+
package p
303+
func _[A any](A) {}
304+
`
305+
306+
fset := token.NewFileSet()
307+
f := mustParse(fset, src)
308+
309+
var conf types.Config
310+
pkg, err := conf.Check(pkgName(src), fset, []*ast.File{f}, nil)
311+
if err != nil {
312+
t.Fatal(err)
313+
}
314+
315+
for _, d := range f.Decls {
316+
if fun, _ := d.(*ast.FuncDecl); fun != nil {
317+
// type parameter A is not found at the start of the function type
318+
if err := types.CheckExpr(fset, pkg, fun.Type.Pos(), fun.Type, nil); err == nil || !strings.Contains(err.Error(), "undefined") {
319+
t.Fatalf("got %s, want undefined error", err)
320+
}
321+
// type parameter A must be found at the end of the function type
322+
if err := types.CheckExpr(fset, pkg, fun.Type.End(), fun.Type, nil); err != nil {
323+
t.Fatal(err)
324+
}
325+
}
326+
}
327+
}

0 commit comments

Comments
 (0)