mirror of
https://github.com/golang/go
synced 2024-11-23 07:10:05 -07:00
go/parser: add resolution tests for type params
For #45104 For #45221 Change-Id: I8966555f4e8844d5b6766d00d48f7a81868ccf40 Reviewed-on: https://go-review.googlesource.com/c/go/+/304453 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
6d2a557a4d
commit
152ca79b73
@ -39,7 +39,11 @@ func TestResolution(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
path := filepath.Join(dir, fi.Name())
|
||||
src := readFile(path) // panics on failure
|
||||
file, err := ParseFile(fset, path, src, 0)
|
||||
var mode Mode
|
||||
if strings.HasSuffix(path, ".go2") {
|
||||
mode = parseTypeParams
|
||||
}
|
||||
file, err := ParseFile(fset, path, src, mode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ const (
|
||||
labelOk // =@labelOk
|
||||
)
|
||||
|
||||
func _ /* =@blankFunc */ () {
|
||||
type T /* =@T */ int
|
||||
|
||||
func _ /* =@blankFunc */ (count /* =@count */ T /* @T */) {
|
||||
x /* =@x1 */ := c /* @cdecl */{}
|
||||
switch x /* =@x2 */ := x /* @x1 */; x /* =@x3 */ := x /* @x2 */.(type) {
|
||||
case c /* @cdecl */:
|
||||
|
24
src/go/parser/testdata/resolution/typeparams.go2
vendored
Normal file
24
src/go/parser/testdata/resolution/typeparams.go2
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2021 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 resolution
|
||||
|
||||
type List /* =@List */ [E /* =@E */ any] []E // @E
|
||||
|
||||
type Pair /* =@Pair */ [L /* =@L */, R /* =@R */ any] struct {
|
||||
Left /* =@Left */ L // @L
|
||||
Right /* =@Right */ R // @R
|
||||
}
|
||||
|
||||
var _ /* =@blank */ = Pair /* @Pair */ [int, string]{}
|
||||
|
||||
type Addable /* =@Addable */ interface {
|
||||
type int64, float64
|
||||
}
|
||||
|
||||
// TODO (#45221): resolve references to T in the signature below.
|
||||
func Add /* =@AddDecl */[T /* =@T */ Addable /* @Addable */](l /* =@l */, r /* =@r */ T) T {
|
||||
var t /* =@t */ T /* @T */
|
||||
return l /* @l */ + r /* @r */ + t /* @t */
|
||||
}
|
Loading…
Reference in New Issue
Block a user