]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: add resolution tests for type params
authorRob Findley <rfindley@google.com>
Wed, 24 Mar 2021 21:36:40 +0000 (17:36 -0400)
committerRobert Findley <rfindley@google.com>
Wed, 31 Mar 2021 02:35:00 +0000 (02:35 +0000)
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>
src/go/parser/resolver_test.go
src/go/parser/testdata/resolution/resolution.src
src/go/parser/testdata/resolution/typeparams.go2 [new file with mode: 0644]

index 018214e4373f28b84d1b1912e28a561768df8736..9ae2844d730f7684a8b8407daf99b748846ce143 100644 (file)
@@ -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)
                        }
index e1ecdb5393742a6b73458104382abe56b66a097b..d76a83d9ed2c6ca5f6a838a4ebb5e57e7c42670d 100644 (file)
@@ -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 */:
diff --git a/src/go/parser/testdata/resolution/typeparams.go2 b/src/go/parser/testdata/resolution/typeparams.go2
new file mode 100644 (file)
index 0000000..922f779
--- /dev/null
@@ -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 */
+}