Skip to content

Commit 3ab2ab9

Browse files
owen-mcmbg
authored andcommitted
Use unique type param names in test
This makes it clearer when changes in test results are due to changes in the standard library.
1 parent 257506b commit 3ab2ab9

File tree

6 files changed

+99
-82
lines changed

6 files changed

+99
-82
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
| genericFunctions.go:25:2:25:33 | generic function instantiation expression | genericFunctions.go:25:2:25:28 | GenericFunctionOneTypeParam | 0 | genericFunctions.go:25:30:25:32 | int |
2-
| genericFunctions.go:26:2:26:36 | generic function instantiation expression | genericFunctions.go:26:2:26:28 | GenericFunctionOneTypeParam | 0 | genericFunctions.go:26:30:26:35 | string |
3-
| genericFunctions.go:44:6:44:48 | generic function instantiation expression | genericFunctions.go:44:6:44:33 | GenericFunctionTwoTypeParams | 0 | genericFunctions.go:44:35:44:40 | string |
4-
| genericFunctions.go:44:6:44:48 | generic function instantiation expression | genericFunctions.go:44:6:44:33 | GenericFunctionTwoTypeParams | 1 | genericFunctions.go:44:43:44:47 | int64 |
5-
| genericFunctions.go:45:6:45:50 | generic function instantiation expression | genericFunctions.go:45:6:45:33 | GenericFunctionTwoTypeParams | 0 | genericFunctions.go:45:35:45:40 | string |
6-
| genericFunctions.go:45:6:45:50 | generic function instantiation expression | genericFunctions.go:45:6:45:33 | GenericFunctionTwoTypeParams | 1 | genericFunctions.go:45:43:45:49 | float64 |
7-
| genericFunctions.go:141:6:141:41 | generic function instantiation expression | genericFunctions.go:141:6:141:33 | GenericFunctionInAnotherFile | 0 | genericFunctions.go:141:35:141:40 | string |
8-
| genericFunctions.go:146:6:146:55 | generic function instantiation expression | genericFunctions.go:146:6:146:47 | selection of GenericFunctionInAnotherPackage | 0 | genericFunctions.go:146:49:146:54 | string |
1+
| genericFunctions.go:27:2:27:33 | generic function instantiation expression | genericFunctions.go:27:2:27:28 | GenericFunctionOneTypeParam | 0 | genericFunctions.go:27:30:27:32 | int |
2+
| genericFunctions.go:28:2:28:36 | generic function instantiation expression | genericFunctions.go:28:2:28:28 | GenericFunctionOneTypeParam | 0 | genericFunctions.go:28:30:28:35 | string |
3+
| genericFunctions.go:46:6:46:48 | generic function instantiation expression | genericFunctions.go:46:6:46:33 | GenericFunctionTwoTypeParams | 0 | genericFunctions.go:46:35:46:40 | string |
4+
| genericFunctions.go:46:6:46:48 | generic function instantiation expression | genericFunctions.go:46:6:46:33 | GenericFunctionTwoTypeParams | 1 | genericFunctions.go:46:43:46:47 | int64 |
5+
| genericFunctions.go:47:6:47:50 | generic function instantiation expression | genericFunctions.go:47:6:47:33 | GenericFunctionTwoTypeParams | 0 | genericFunctions.go:47:35:47:40 | string |
6+
| genericFunctions.go:47:6:47:50 | generic function instantiation expression | genericFunctions.go:47:6:47:33 | GenericFunctionTwoTypeParams | 1 | genericFunctions.go:47:43:47:49 | float64 |
7+
| genericFunctions.go:143:6:143:41 | generic function instantiation expression | genericFunctions.go:143:6:143:33 | GenericFunctionInAnotherFile | 0 | genericFunctions.go:143:35:143:40 | string |
8+
| genericFunctions.go:148:6:148:55 | generic function instantiation expression | genericFunctions.go:148:6:148:47 | selection of GenericFunctionInAnotherPackage | 0 | genericFunctions.go:148:49:148:54 | string |
Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
| E | Ordered |
2+
| E | any |
23
| E | comparable |
3-
| E | interface { } |
4-
| E1 | interface { } |
5-
| E2 | interface { } |
6-
| Edge | EdgeConstraint |
7-
| Edge | interface { } |
4+
| E | interface { ~uint16 \| ~uint32 } |
5+
| E1 | any |
6+
| E2 | any |
87
| F | floaty |
9-
| K | comparable |
10-
| Node | NodeConstraint |
11-
| Node | interface { } |
12-
| S | interface { } |
8+
| K | any |
9+
| N | interface { int64 \| uint64 } |
1310
| S | interface { ~[]E } |
1411
| S1 | interface { ~[]E1 } |
1512
| S2 | interface { ~[]E2 } |
16-
| SF2 | interface { } |
17-
| SG2 | interface { } |
13+
| Slice | interface { ~[]E } |
1814
| T | Ordered |
15+
| T | any |
1916
| T | comparable |
2017
| T | interface { string \| []uint8 } |
21-
| T | interface { } |
22-
| T1 | interface { } |
23-
| T2 | interface { } |
24-
| TF1 | interface { } |
25-
| TF2 | interface { } |
26-
| TG1 | interface { } |
27-
| TG2 | interface { } |
28-
| U | interface { } |
29-
| V | interface { int64 \| float64 } |
18+
| T1 | any |
19+
| T2 | any |
20+
| TP101 | any |
21+
| TP102 | comparable |
22+
| TP103 | interface { int64 \| float64 } |
23+
| TP104 | interface { } |
24+
| TP105 | any |
25+
| TP106 | any |
26+
| TP107 | interface { } |
27+
| TP108 | interface { } |
28+
| TP109 | any |
29+
| TP110 | any |
30+
| TP111 | any |
31+
| TP112 | any |
32+
| TP113 | any |
33+
| TP114 | any |
34+
| TP115 | any |
35+
| TP116 | any |
36+
| TP117 | any |
37+
| TP118 | NodeConstraint |
38+
| TP119 | EdgeConstraint |
39+
| TP120 | NodeConstraint |
40+
| TP121 | EdgeConstraint |
41+
| TP122 | NodeConstraint |
42+
| TP123 | EdgeConstraint |
43+
| TP200 | any |
44+
| V | any |
3045
| bytes | interface { []uint8 \| string } |

go/ql/test/library-tests/semmle/go/Function/genericFunctions.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ package main
22

33
import "github.com/anotherpkg"
44

5-
type T1 map[string][]string
6-
type T2 T1
5+
type DefinedType1 map[string][]string
6+
type DefinedType2 DefinedType1
7+
type AliasType1 = DefinedType2
8+
type AliasType2 = AliasType1
79

810
// A generic function with one type parameter
9-
func GenericFunctionOneTypeParam[T any](t T) T {
10-
var r T
11+
func GenericFunctionOneTypeParam[TP101 any](t TP101) TP101 {
12+
var r TP101
1113
return r
1214
}
1315

1416
// A generic function with two type parameter
15-
func GenericFunctionTwoTypeParams[K comparable, V int64 | float64](m map[K]V) V {
16-
var s V
17+
func GenericFunctionTwoTypeParams[TP102 comparable, TP103 int64 | float64](m map[TP102]TP103) TP103 {
18+
var s TP103
1719
for _, v := range m {
1820
s += v
1921
}
@@ -78,24 +80,24 @@ func generic_functions() {
7880
aliasedMap["key"][0] = "new value"
7981
}
8082

81-
type GenericStruct1[T any] struct {
83+
type GenericStruct1[TP104 interface{}] struct {
8284
}
8385

84-
type GenericStruct2[S, T any] struct {
86+
type GenericStruct2[TP105, TP106 any] struct {
8587
}
8688

87-
func (x GenericStruct1[TF1]) f1() TF1 {
88-
var r TF1
89+
func (x GenericStruct1[TP107]) f1() TP107 {
90+
var r TP107
8991
return r
9092
}
9193

92-
func (x *GenericStruct1[TG1]) g1() {
94+
func (x *GenericStruct1[TP108]) g1() {
9395
}
9496

95-
func (x GenericStruct2[SF2, TF2]) f2() {
97+
func (x GenericStruct2[TP109, TP110]) f2() {
9698
}
9799

98-
func (x *GenericStruct2[SG2, TG2]) g2() {
100+
func (x *GenericStruct2[TP111, TP112]) g2() {
99101
}
100102

101103
func call_methods_with_generic_receiver() {
@@ -108,34 +110,34 @@ func call_methods_with_generic_receiver() {
108110
x2.g2()
109111
}
110112

111-
type Element[S any] struct {
112-
list *List[S]
113+
type Element[TP113 any] struct {
114+
list *List[TP113]
113115
}
114116

115-
type List[T any] struct {
116-
root Element[T]
117+
type List[TP114 any] struct {
118+
root Element[TP114]
117119
}
118120

119121
// Len is the number of elements in the list.
120-
func (l *List[U]) MyLen() int {
122+
func (l *List[TP115]) MyLen() int {
121123
return 0
122124
}
123125

124-
type NodeConstraint[Edge any] interface {
125-
Edges() []Edge
126+
type NodeConstraint[TP116 any] interface {
127+
Edges() []TP116
126128
}
127129

128-
type EdgeConstraint[Node any] interface {
129-
Nodes() (from, to Node)
130+
type EdgeConstraint[TP117 any] interface {
131+
Nodes() (from, to TP117)
130132
}
131133

132-
type Graph[Node NodeConstraint[Edge], Edge EdgeConstraint[Node]] struct{}
134+
type Graph[TP118 NodeConstraint[TP119], TP119 EdgeConstraint[TP118]] struct{}
133135

134-
func New[Node NodeConstraint[Edge], Edge EdgeConstraint[Node]](nodes []Node) *Graph[Node, Edge] {
136+
func New[TP120 NodeConstraint[TP121], TP121 EdgeConstraint[TP120]](nodes []TP120) *Graph[TP120, TP121] {
135137
return nil
136138
}
137139

138-
func (g *Graph[Node, Edge]) ShortestPath(from, to Node) []Edge { return []Edge{} }
140+
func (g *Graph[TP122, TP123]) ShortestPath(from, to TP122) []TP123 { return []TP123{} }
139141

140142
func callFunctionsInAnotherFile() {
141143
_ = GenericFunctionInAnotherFile[string]("world")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
func GenericFunctionInAnotherFile[T any](t T) T {
4-
var r T
3+
func GenericFunctionInAnotherFile[TP200 any](t TP200) TP200 {
4+
var r TP200
55
return r
66
}

go/ql/test/library-tests/semmle/go/Function/getParameter.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
| genericFunctions2.go:3:6:3:33 | GenericFunctionInAnotherFile | 0 | genericFunctions2.go:3:42:3:42 | t |
2-
| genericFunctions.go:9:6:9:32 | GenericFunctionOneTypeParam | 0 | genericFunctions.go:9:41:9:41 | t |
3-
| genericFunctions.go:15:6:15:33 | GenericFunctionTwoTypeParams | 0 | genericFunctions.go:15:68:15:68 | m |
4-
| genericFunctions.go:87:30:87:31 | f1 | -1 | genericFunctions.go:87:7:87:7 | x |
5-
| genericFunctions.go:92:31:92:32 | g1 | -1 | genericFunctions.go:92:7:92:7 | x |
6-
| genericFunctions.go:95:35:95:36 | f2 | -1 | genericFunctions.go:95:7:95:7 | x |
7-
| genericFunctions.go:98:36:98:37 | g2 | -1 | genericFunctions.go:98:7:98:7 | x |
8-
| genericFunctions.go:120:19:120:23 | MyLen | -1 | genericFunctions.go:120:7:120:7 | l |
9-
| genericFunctions.go:134:6:134:8 | New | 0 | genericFunctions.go:134:64:134:68 | nodes |
10-
| genericFunctions.go:138:29:138:40 | ShortestPath | 0 | genericFunctions.go:138:42:138:45 | from |
11-
| genericFunctions.go:138:29:138:40 | ShortestPath | 1 | genericFunctions.go:138:48:138:49 | to |
12-
| genericFunctions.go:138:29:138:40 | ShortestPath | -1 | genericFunctions.go:138:7:138:7 | g |
1+
| genericFunctions2.go:3:6:3:33 | GenericFunctionInAnotherFile | 0 | genericFunctions2.go:3:46:3:46 | t |
2+
| genericFunctions.go:11:6:11:32 | GenericFunctionOneTypeParam | 0 | genericFunctions.go:11:45:11:45 | t |
3+
| genericFunctions.go:17:6:17:33 | GenericFunctionTwoTypeParams | 0 | genericFunctions.go:17:76:17:76 | m |
4+
| genericFunctions.go:89:32:89:33 | f1 | -1 | genericFunctions.go:89:7:89:7 | x |
5+
| genericFunctions.go:94:33:94:34 | g1 | -1 | genericFunctions.go:94:7:94:7 | x |
6+
| genericFunctions.go:97:39:97:40 | f2 | -1 | genericFunctions.go:97:7:97:7 | x |
7+
| genericFunctions.go:100:40:100:41 | g2 | -1 | genericFunctions.go:100:7:100:7 | x |
8+
| genericFunctions.go:122:23:122:27 | MyLen | -1 | genericFunctions.go:122:7:122:7 | l |
9+
| genericFunctions.go:136:6:136:8 | New | 0 | genericFunctions.go:136:68:136:72 | nodes |
10+
| genericFunctions.go:140:31:140:42 | ShortestPath | 0 | genericFunctions.go:140:44:140:47 | from |
11+
| genericFunctions.go:140:31:140:42 | ShortestPath | 1 | genericFunctions.go:140:50:140:51 | to |
12+
| genericFunctions.go:140:31:140:42 | ShortestPath | -1 | genericFunctions.go:140:7:140:7 | g |
1313
| main.go:7:6:7:7 | f1 | 0 | main.go:7:9:7:9 | x |
1414
| main.go:9:12:9:13 | f2 | 0 | main.go:9:15:9:15 | x |
1515
| main.go:9:12:9:13 | f2 | 1 | main.go:9:18:9:18 | y |
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
| genericFunctions2.go:3:1:6:1 | function declaration | FuncDecl | 0 | genericFunctions2.go:3:35:3:39 | type parameter declaration | 0 | genericFunctions2.go:3:35:3:35 | T | genericFunctions2.go:3:37:3:39 | any | interface { } |
2-
| genericFunctions.go:9:1:12:1 | function declaration | FuncDecl | 0 | genericFunctions.go:9:34:9:38 | type parameter declaration | 0 | genericFunctions.go:9:34:9:34 | T | genericFunctions.go:9:36:9:38 | any | interface { } |
3-
| genericFunctions.go:15:1:21:1 | function declaration | FuncDecl | 0 | genericFunctions.go:15:35:15:46 | type parameter declaration | 0 | genericFunctions.go:15:35:15:35 | K | genericFunctions.go:15:37:15:46 | comparable | comparable |
4-
| genericFunctions.go:15:1:21:1 | function declaration | FuncDecl | 1 | genericFunctions.go:15:49:15:65 | type parameter declaration | 0 | genericFunctions.go:15:49:15:49 | V | genericFunctions.go:15:51:15:65 | type set literal | interface { int64 \| float64 } |
5-
| genericFunctions.go:81:6:82:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:81:21:81:25 | type parameter declaration | 0 | genericFunctions.go:81:21:81:21 | T | genericFunctions.go:81:23:81:25 | any | interface { } |
6-
| genericFunctions.go:84:6:85:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:84:21:84:28 | type parameter declaration | 0 | genericFunctions.go:84:21:84:21 | S | genericFunctions.go:84:26:84:28 | any | interface { } |
7-
| genericFunctions.go:84:6:85:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:84:21:84:28 | type parameter declaration | 1 | genericFunctions.go:84:24:84:24 | T | genericFunctions.go:84:26:84:28 | any | interface { } |
8-
| genericFunctions.go:111:6:113:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:111:14:111:18 | type parameter declaration | 0 | genericFunctions.go:111:14:111:14 | S | genericFunctions.go:111:16:111:18 | any | interface { } |
9-
| genericFunctions.go:115:6:117:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:115:11:115:15 | type parameter declaration | 0 | genericFunctions.go:115:11:115:11 | T | genericFunctions.go:115:13:115:15 | any | interface { } |
10-
| genericFunctions.go:124:6:126:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:124:21:124:28 | type parameter declaration | 0 | genericFunctions.go:124:21:124:24 | Edge | genericFunctions.go:124:26:124:28 | any | interface { } |
11-
| genericFunctions.go:128:6:130:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:128:21:128:28 | type parameter declaration | 0 | genericFunctions.go:128:21:128:24 | Node | genericFunctions.go:128:26:128:28 | any | interface { } |
12-
| genericFunctions.go:132:6:132:73 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:132:12:132:36 | type parameter declaration | 0 | genericFunctions.go:132:12:132:15 | Node | genericFunctions.go:132:17:132:36 | generic type instantiation expression | NodeConstraint |
13-
| genericFunctions.go:132:6:132:73 | type declaration specifier | TypeSpec | 1 | genericFunctions.go:132:39:132:63 | type parameter declaration | 0 | genericFunctions.go:132:39:132:42 | Edge | genericFunctions.go:132:44:132:63 | generic type instantiation expression | EdgeConstraint |
14-
| genericFunctions.go:134:1:136:1 | function declaration | FuncDecl | 0 | genericFunctions.go:134:10:134:34 | type parameter declaration | 0 | genericFunctions.go:134:10:134:13 | Node | genericFunctions.go:134:15:134:34 | generic type instantiation expression | NodeConstraint |
15-
| genericFunctions.go:134:1:136:1 | function declaration | FuncDecl | 1 | genericFunctions.go:134:37:134:61 | type parameter declaration | 0 | genericFunctions.go:134:37:134:40 | Edge | genericFunctions.go:134:42:134:61 | generic type instantiation expression | EdgeConstraint |
1+
| genericFunctions2.go:3:1:6:1 | function declaration | FuncDecl | 0 | genericFunctions2.go:3:35:3:43 | type parameter declaration | 0 | genericFunctions2.go:3:35:3:39 | TP200 | genericFunctions2.go:3:41:3:43 | any | any |
2+
| genericFunctions.go:11:1:14:1 | function declaration | FuncDecl | 0 | genericFunctions.go:11:34:11:42 | type parameter declaration | 0 | genericFunctions.go:11:34:11:38 | TP101 | genericFunctions.go:11:40:11:42 | any | any |
3+
| genericFunctions.go:17:1:23:1 | function declaration | FuncDecl | 0 | genericFunctions.go:17:35:17:50 | type parameter declaration | 0 | genericFunctions.go:17:35:17:39 | TP102 | genericFunctions.go:17:41:17:50 | comparable | comparable |
4+
| genericFunctions.go:17:1:23:1 | function declaration | FuncDecl | 1 | genericFunctions.go:17:53:17:73 | type parameter declaration | 0 | genericFunctions.go:17:53:17:57 | TP103 | genericFunctions.go:17:59:17:73 | type set literal | interface { int64 \| float64 } |
5+
| genericFunctions.go:83:6:84:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:83:21:83:37 | type parameter declaration | 0 | genericFunctions.go:83:21:83:25 | TP104 | genericFunctions.go:83:27:83:37 | interface type | interface { } |
6+
| genericFunctions.go:86:6:87:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:86:21:86:36 | type parameter declaration | 0 | genericFunctions.go:86:21:86:25 | TP105 | genericFunctions.go:86:34:86:36 | any | any |
7+
| genericFunctions.go:86:6:87:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:86:21:86:36 | type parameter declaration | 1 | genericFunctions.go:86:28:86:32 | TP106 | genericFunctions.go:86:34:86:36 | any | any |
8+
| genericFunctions.go:113:6:115:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:113:14:113:22 | type parameter declaration | 0 | genericFunctions.go:113:14:113:18 | TP113 | genericFunctions.go:113:20:113:22 | any | any |
9+
| genericFunctions.go:117:6:119:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:117:11:117:19 | type parameter declaration | 0 | genericFunctions.go:117:11:117:15 | TP114 | genericFunctions.go:117:17:117:19 | any | any |
10+
| genericFunctions.go:126:6:128:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:126:21:126:29 | type parameter declaration | 0 | genericFunctions.go:126:21:126:25 | TP116 | genericFunctions.go:126:27:126:29 | any | any |
11+
| genericFunctions.go:130:6:132:1 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:130:21:130:29 | type parameter declaration | 0 | genericFunctions.go:130:21:130:25 | TP117 | genericFunctions.go:130:27:130:29 | any | any |
12+
| genericFunctions.go:134:6:134:77 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:134:12:134:38 | type parameter declaration | 0 | genericFunctions.go:134:12:134:16 | TP118 | genericFunctions.go:134:18:134:38 | generic type instantiation expression | NodeConstraint |
13+
| genericFunctions.go:134:6:134:77 | type declaration specifier | TypeSpec | 1 | genericFunctions.go:134:41:134:67 | type parameter declaration | 0 | genericFunctions.go:134:41:134:45 | TP119 | genericFunctions.go:134:47:134:67 | generic type instantiation expression | EdgeConstraint |
14+
| genericFunctions.go:136:1:138:1 | function declaration | FuncDecl | 0 | genericFunctions.go:136:10:136:36 | type parameter declaration | 0 | genericFunctions.go:136:10:136:14 | TP120 | genericFunctions.go:136:16:136:36 | generic type instantiation expression | NodeConstraint |
15+
| genericFunctions.go:136:1:138:1 | function declaration | FuncDecl | 1 | genericFunctions.go:136:39:136:65 | type parameter declaration | 0 | genericFunctions.go:136:39:136:43 | TP121 | genericFunctions.go:136:45:136:65 | generic type instantiation expression | EdgeConstraint |

0 commit comments

Comments
 (0)