[go] test: more tests for generic methods

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Apr 9, 2026, 11:50:47 AM (16 hours ago) Apr 9
to Mark Freeman, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Robert Griesemer, golang-co...@googlegroups.com

Gopher Robot submitted the change with unreviewed changes

Unreviewed changes

1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: test/genmeth1.go
Insertions: 16, Deletions: 14.

@@ -8,40 +8,42 @@

package main

-import "fmt"
+import (
+ "fmt"
+ "strings"
+)

type S[A, B any] struct {
- f A
- g B
+ a A
+ b B
}

func (s S[A, B]) m() string {
- return typeStr(s.f, s.g)
+ return typeStr(s.a, s.b)
}

func (s S[A, B]) n[C, D any]() string {
- var x C
- var y D
- return typeStr(s.f, s.g, x, y)
+ var c C
+ var d D
+ return typeStr(s.a, s.b, c, d)
}

func typeStr(args ...any) string {
s := ""
- for i := 0; i < len(args); i++ {
+ for i, arg := range args {
if i > 0 {
s += "->"
}
- // remove "main." prefix for brevity
- s += fmt.Sprintf("%T", args[i])[5:]
+ s += strings.TrimPrefix(fmt.Sprintf("%T", arg), "main.") // trim for brevity
}
return s
}

func main() {
- type T1 int
- type T2 int
- type T3 int
- type T4 int
+ type T1 int8
+ type T2 int16
+ type T3 int32
+ type T4 int64

// method calls
// static dictionary on type
```

Change information

Commit message:
test: more tests for generic methods

These tests verify that generic method type arguments are ordered
correctly for a variety of expression forms and dictionary kinds.
Change-Id: I067206d1e97d5350d6fcc3983f5a6ef24a782214
Reviewed-by: Robert Griesemer <g...@google.com>
Auto-Submit: Mark Freeman <markf...@google.com>
Files:
  • A test/genmeth1.go
Change size: M
Delta: 1 file changed, 144 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Robert Griesemer
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I067206d1e97d5350d6fcc3983f5a6ef24a782214
Gerrit-Change-Number: 764200
Gerrit-PatchSet: 3
Gerrit-Owner: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Mark Freeman <markf...@google.com>
Gerrit-Reviewer: Robert Griesemer <g...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages