Skip to content

Commit 9aafcbc

Browse files
committed
Add test for multiple anonymous type parameters
1 parent 90f7b30 commit 9aafcbc

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

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

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
numberOfTypeParameters
2+
| genericFunctions2.go:3:6:3:33 | GenericFunctionInAnotherFile | 1 |
3+
| genericFunctions.go:9:6:9:32 | GenericFunctionOneTypeParam | 1 |
4+
| genericFunctions.go:15:6:15:33 | GenericFunctionTwoTypeParams | 2 |
5+
| genericFunctions.go:81:6:81:19 | GenericStruct1 | 1 |
6+
| genericFunctions.go:84:6:84:19 | GenericStruct2 | 2 |
7+
| genericFunctions.go:87:30:87:31 | f1 | 1 |
8+
| genericFunctions.go:92:31:92:32 | g1 | 1 |
9+
| genericFunctions.go:95:35:95:36 | f2 | 2 |
10+
| genericFunctions.go:98:36:98:37 | g2 | 2 |
11+
| genericFunctions.go:111:6:111:12 | Element | 1 |
12+
| genericFunctions.go:115:6:115:9 | List | 1 |
13+
| genericFunctions.go:120:19:120:23 | MyLen | 1 |
14+
| genericFunctions.go:124:6:124:19 | NodeConstraint | 1 |
15+
| genericFunctions.go:128:6:128:19 | EdgeConstraint | 1 |
16+
| genericFunctions.go:132:6:132:10 | Graph | 2 |
17+
| genericFunctions.go:134:6:134:8 | New | 2 |
18+
| genericFunctions.go:138:29:138:40 | ShortestPath | 2 |
19+
| genericFunctions.go:150:6:150:36 | multipleAnonymousTypeParamsFunc | 1 |
20+
| genericFunctions.go:152:6:152:36 | multipleAnonymousTypeParamsType | 1 |
21+
| genericFunctions.go:154:51:154:51 | f | 1 |
22+
#select
123
| cmp.Compare | 0 | T | Ordered |
224
| cmp.Less | 0 | T | Ordered |
325
| cmp.Or | 0 | T | comparable |
@@ -26,30 +48,56 @@
2648
| codeql-go-tests/function.New | 0 | Node | NodeConstraint |
2749
| codeql-go-tests/function.New | 1 | Edge | EdgeConstraint |
2850
| codeql-go-tests/function.NodeConstraint | 0 | Edge | interface { } |
51+
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 0 | _ | interface { } |
52+
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 1 | _ | interface { string } |
53+
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 2 | _ | interface { } |
54+
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 0 | _ | interface { } |
55+
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 1 | _ | interface { string } |
56+
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 2 | _ | interface { } |
57+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 0 | _ | interface { } |
58+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 1 | _ | interface { string } |
59+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 2 | _ | interface { } |
2960
| github.com/anotherpkg.GenericFunctionInAnotherPackage | 0 | T | interface { } |
61+
| internal/abi.Escape | 0 | T | interface { } |
3062
| internal/bytealg.HashStr | 0 | T | interface { string \| []uint8 } |
3163
| internal/bytealg.HashStrRev | 0 | T | interface { string \| []uint8 } |
3264
| internal/bytealg.IndexRabinKarp | 0 | T | interface { string \| []uint8 } |
3365
| internal/bytealg.LastIndexRabinKarp | 0 | T | interface { string \| []uint8 } |
66+
| internal/runtime/atomic.Pointer.CompareAndSwap | 0 | T | interface { } |
67+
| internal/runtime/atomic.Pointer.CompareAndSwapNoWB | 0 | T | interface { } |
68+
| internal/runtime/atomic.Pointer.Load | 0 | T | interface { } |
69+
| internal/runtime/atomic.Pointer.Store | 0 | T | interface { } |
70+
| internal/runtime/atomic.Pointer.StoreNoWB | 0 | T | interface { } |
71+
| iter.Pull | 0 | V | interface { } |
72+
| iter.Pull2 | 0 | K | interface { } |
73+
| iter.Pull2 | 1 | V | interface { } |
74+
| iter.Seq | 0 | V | interface { } |
75+
| iter.Seq2 | 0 | K | interface { } |
76+
| iter.Seq2 | 1 | V | interface { } |
77+
| reflect.rangeNum | 1 | N | interface { int64 \| uint64 } |
3478
| runtime.fandbits | 0 | F | floaty |
3579
| runtime.fmax | 0 | F | floaty |
3680
| runtime.fmin | 0 | F | floaty |
3781
| runtime.forbits | 0 | F | floaty |
3882
| runtime.noEscapePtr | 0 | T | interface { } |
39-
| runtime/internal/atomic.Pointer.CompareAndSwap | 0 | T | interface { } |
40-
| runtime/internal/atomic.Pointer.CompareAndSwapNoWB | 0 | T | interface { } |
41-
| runtime/internal/atomic.Pointer.Load | 0 | T | interface { } |
42-
| runtime/internal/atomic.Pointer.Store | 0 | T | interface { } |
43-
| runtime/internal/atomic.Pointer.StoreNoWB | 0 | T | interface { } |
83+
| slices.All | 0 | Slice | interface { ~[]E } |
84+
| slices.All | 1 | E | interface { } |
85+
| slices.AppendSeq | 0 | Slice | interface { ~[]E } |
86+
| slices.AppendSeq | 1 | E | interface { } |
87+
| slices.Backward | 0 | Slice | interface { ~[]E } |
88+
| slices.Backward | 1 | E | interface { } |
4489
| slices.BinarySearch | 0 | S | interface { ~[]E } |
4590
| slices.BinarySearch | 1 | E | Ordered |
4691
| slices.BinarySearchFunc | 0 | S | interface { ~[]E } |
4792
| slices.BinarySearchFunc | 1 | E | interface { } |
4893
| slices.BinarySearchFunc | 2 | T | interface { } |
94+
| slices.Chunk | 0 | Slice | interface { ~[]E } |
95+
| slices.Chunk | 1 | E | interface { } |
4996
| slices.Clip | 0 | S | interface { ~[]E } |
5097
| slices.Clip | 1 | E | interface { } |
5198
| slices.Clone | 0 | S | interface { ~[]E } |
5299
| slices.Clone | 1 | E | interface { } |
100+
| slices.Collect | 0 | E | interface { } |
53101
| slices.Compact | 0 | S | interface { ~[]E } |
54102
| slices.Compact | 1 | E | comparable |
55103
| slices.CompactFunc | 0 | S | interface { ~[]E } |
@@ -96,6 +144,8 @@
96144
| slices.Min | 1 | E | Ordered |
97145
| slices.MinFunc | 0 | S | interface { ~[]E } |
98146
| slices.MinFunc | 1 | E | interface { } |
147+
| slices.Repeat | 0 | S | interface { ~[]E } |
148+
| slices.Repeat | 1 | E | interface { } |
99149
| slices.Replace | 0 | S | interface { ~[]E } |
100150
| slices.Replace | 1 | E | interface { } |
101151
| slices.Reverse | 0 | S | interface { ~[]E } |
@@ -106,6 +156,11 @@
106156
| slices.SortFunc | 1 | E | interface { } |
107157
| slices.SortStableFunc | 0 | S | interface { ~[]E } |
108158
| slices.SortStableFunc | 1 | E | interface { } |
159+
| slices.Sorted | 0 | E | Ordered |
160+
| slices.SortedFunc | 0 | E | interface { } |
161+
| slices.SortedStableFunc | 0 | E | interface { } |
162+
| slices.Values | 0 | Slice | interface { ~[]E } |
163+
| slices.Values | 1 | E | interface { } |
109164
| slices.breakPatternsCmpFunc | 0 | E | interface { } |
110165
| slices.breakPatternsOrdered | 0 | E | Ordered |
111166
| slices.choosePivotCmpFunc | 0 | E | interface { } |
@@ -141,11 +196,12 @@
141196
| slices.stableCmpFunc | 0 | E | interface { } |
142197
| slices.stableOrdered | 0 | E | Ordered |
143198
| slices.startIdx | 0 | E | interface { } |
144-
| slices.swap | 0 | E | interface { } |
145199
| slices.swapRangeCmpFunc | 0 | E | interface { } |
146200
| slices.swapRangeOrdered | 0 | E | Ordered |
147201
| slices.symMergeCmpFunc | 0 | E | interface { } |
148202
| slices.symMergeOrdered | 0 | E | Ordered |
203+
| strconv.bsearch | 0 | S | interface { ~[]E } |
204+
| strconv.bsearch | 1 | E | interface { ~uint16 \| ~uint32 } |
149205
| sync.OnceValue | 0 | T | interface { } |
150206
| sync.OnceValues | 0 | T1 | interface { } |
151207
| sync.OnceValues | 1 | T2 | interface { } |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import go
22

3+
query predicate numberOfTypeParameters(TypeParamParentEntity parent, int n) {
4+
exists(string file | file != "" | parent.hasLocationInfo(file, _, _, _, _)) and
5+
n = strictcount(TypeParamType tpt | tpt.getParent() = parent)
6+
}
7+
38
from TypeParamType tpt, TypeParamParentEntity ty
49
where ty = tpt.getParent()
510
select ty.getQualifiedName(), tpt.getIndex(), tpt.getParamName(), tpt.getConstraint().pp()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,9 @@ func callFunctionsInAnotherPackage() {
146146
_ = anotherpkg.GenericFunctionInAnotherPackage[string]("world")
147147
_ = anotherpkg.GenericFunctionInAnotherPackage("world")
148148
}
149+
150+
func multipleAnonymousTypeParamsFunc[_ any, _ string, _ any]() {}
151+
152+
type multipleAnonymousTypeParamsType[_ any, _ string, _ any] struct{}
153+
154+
func (x multipleAnonymousTypeParamsType[_, _, _]) f() {}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| genericFunctions.go:138:29:138:40 | ShortestPath | 0 | genericFunctions.go:138:42:138:45 | from |
1111
| genericFunctions.go:138:29:138:40 | ShortestPath | 1 | genericFunctions.go:138:48:138:49 | to |
1212
| genericFunctions.go:138:29:138:40 | ShortestPath | -1 | genericFunctions.go:138:7:138:7 | g |
13+
| genericFunctions.go:154:51:154:51 | f | -1 | genericFunctions.go:154:7:154:7 | x |
1314
| main.go:7:6:7:7 | f1 | 0 | main.go:7:9:7:9 | x |
1415
| main.go:9:12:9:13 | f2 | 0 | main.go:9:15:9:15 | x |
1516
| main.go:9:12:9:13 | f2 | 1 | main.go:9:18:9:18 | y |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
| 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 |
1414
| 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 |
1515
| 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 |
16+
| genericFunctions.go:150:1:150:65 | function declaration | FuncDecl | 0 | genericFunctions.go:150:38:150:42 | type parameter declaration | 0 | genericFunctions.go:150:38:150:38 | _ | genericFunctions.go:150:40:150:42 | any | interface { } |
17+
| genericFunctions.go:150:1:150:65 | function declaration | FuncDecl | 1 | genericFunctions.go:150:45:150:52 | type parameter declaration | 0 | genericFunctions.go:150:45:150:45 | _ | genericFunctions.go:150:47:150:52 | string | interface { string } |
18+
| genericFunctions.go:150:1:150:65 | function declaration | FuncDecl | 2 | genericFunctions.go:150:55:150:59 | type parameter declaration | 0 | genericFunctions.go:150:55:150:55 | _ | genericFunctions.go:150:57:150:59 | any | interface { } |
19+
| genericFunctions.go:152:6:152:69 | type declaration specifier | TypeSpec | 0 | genericFunctions.go:152:38:152:42 | type parameter declaration | 0 | genericFunctions.go:152:38:152:38 | _ | genericFunctions.go:152:40:152:42 | any | interface { } |
20+
| genericFunctions.go:152:6:152:69 | type declaration specifier | TypeSpec | 1 | genericFunctions.go:152:45:152:52 | type parameter declaration | 0 | genericFunctions.go:152:45:152:45 | _ | genericFunctions.go:152:47:152:52 | string | interface { string } |
21+
| genericFunctions.go:152:6:152:69 | type declaration specifier | TypeSpec | 2 | genericFunctions.go:152:55:152:59 | type parameter declaration | 0 | genericFunctions.go:152:55:152:55 | _ | genericFunctions.go:152:57:152:59 | any | interface { } |

0 commit comments

Comments
 (0)