Skip to content

Commit 1c0f21f

Browse files
committed
Go: Expose new TypeParamType column and use in test
1 parent 37454ab commit 1c0f21f

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

go/ql/lib/semmle/go/Types.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class TypeParamType extends @typeparamtype, CompositeType {
395395
/** Gets the index of this type parameter type. */
396396
int getIndex() { typeparam(this, _, _, _, result, _) }
397397

398+
/** Holds if this type parameter type is declared as part of a receiver */
399+
boolean isFromReceiver() { typeparam(this, _, _, _, _, result) }
400+
398401
override string pp() { result = this.getParamName() }
399402

400403
/**

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

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ numberOfTypeParameters
2020
| genericFunctions.go:152:6:152:36 | multipleAnonymousTypeParamsType | 3 |
2121
| genericFunctions.go:154:51:154:51 | f | 3 |
2222
#select
23-
| codeql-go-tests/function.EdgeConstraint | 0 | Node | interface { } |
24-
| codeql-go-tests/function.Element | 0 | S | interface { } |
25-
| codeql-go-tests/function.GenericFunctionInAnotherFile | 0 | T | interface { } |
26-
| codeql-go-tests/function.GenericFunctionOneTypeParam | 0 | T | interface { } |
27-
| codeql-go-tests/function.GenericFunctionTwoTypeParams | 0 | K | comparable |
28-
| codeql-go-tests/function.GenericFunctionTwoTypeParams | 1 | V | interface { int64 \| float64 } |
29-
| codeql-go-tests/function.GenericStruct1 | 0 | T | interface { } |
30-
| codeql-go-tests/function.GenericStruct1.f1 | 0 | TF1 | interface { } |
31-
| codeql-go-tests/function.GenericStruct1.g1 | 0 | TG1 | interface { } |
32-
| codeql-go-tests/function.GenericStruct2 | 0 | S | interface { } |
33-
| codeql-go-tests/function.GenericStruct2 | 1 | T | interface { } |
34-
| codeql-go-tests/function.GenericStruct2.f2 | 0 | SF2 | interface { } |
35-
| codeql-go-tests/function.GenericStruct2.f2 | 1 | TF2 | interface { } |
36-
| codeql-go-tests/function.GenericStruct2.g2 | 0 | SG2 | interface { } |
37-
| codeql-go-tests/function.GenericStruct2.g2 | 1 | TG2 | interface { } |
38-
| codeql-go-tests/function.Graph | 0 | Node | NodeConstraint |
39-
| codeql-go-tests/function.Graph | 1 | Edge | EdgeConstraint |
40-
| codeql-go-tests/function.Graph.ShortestPath | 0 | Node | NodeConstraint |
41-
| codeql-go-tests/function.Graph.ShortestPath | 1 | Edge | EdgeConstraint |
42-
| codeql-go-tests/function.List | 0 | T | interface { } |
43-
| codeql-go-tests/function.List.MyLen | 0 | U | interface { } |
44-
| codeql-go-tests/function.New | 0 | Node | NodeConstraint |
45-
| codeql-go-tests/function.New | 1 | Edge | EdgeConstraint |
46-
| codeql-go-tests/function.NodeConstraint | 0 | Edge | interface { } |
47-
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 0 | _ | interface { } |
48-
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 1 | _ | interface { string } |
49-
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 2 | _ | interface { } |
50-
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 0 | _ | interface { } |
51-
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 1 | _ | interface { string } |
52-
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 2 | _ | interface { } |
53-
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 0 | _ | interface { } |
54-
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 1 | _ | interface { string } |
55-
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 2 | _ | interface { } |
23+
| codeql-go-tests/function.EdgeConstraint | 0 | false | Node | interface { } |
24+
| codeql-go-tests/function.Element | 0 | false | S | interface { } |
25+
| codeql-go-tests/function.GenericFunctionInAnotherFile | 0 | false | T | interface { } |
26+
| codeql-go-tests/function.GenericFunctionOneTypeParam | 0 | false | T | interface { } |
27+
| codeql-go-tests/function.GenericFunctionTwoTypeParams | 0 | false | K | comparable |
28+
| codeql-go-tests/function.GenericFunctionTwoTypeParams | 1 | false | V | interface { int64 \| float64 } |
29+
| codeql-go-tests/function.GenericStruct1 | 0 | false | T | interface { } |
30+
| codeql-go-tests/function.GenericStruct1.f1 | 0 | true | TF1 | interface { } |
31+
| codeql-go-tests/function.GenericStruct1.g1 | 0 | true | TG1 | interface { } |
32+
| codeql-go-tests/function.GenericStruct2 | 0 | false | S | interface { } |
33+
| codeql-go-tests/function.GenericStruct2 | 1 | false | T | interface { } |
34+
| codeql-go-tests/function.GenericStruct2.f2 | 0 | true | SF2 | interface { } |
35+
| codeql-go-tests/function.GenericStruct2.f2 | 1 | true | TF2 | interface { } |
36+
| codeql-go-tests/function.GenericStruct2.g2 | 0 | true | SG2 | interface { } |
37+
| codeql-go-tests/function.GenericStruct2.g2 | 1 | true | TG2 | interface { } |
38+
| codeql-go-tests/function.Graph | 0 | false | Node | NodeConstraint |
39+
| codeql-go-tests/function.Graph | 1 | false | Edge | EdgeConstraint |
40+
| codeql-go-tests/function.Graph.ShortestPath | 0 | true | Node | NodeConstraint |
41+
| codeql-go-tests/function.Graph.ShortestPath | 1 | true | Edge | EdgeConstraint |
42+
| codeql-go-tests/function.List | 0 | false | T | interface { } |
43+
| codeql-go-tests/function.List.MyLen | 0 | true | U | interface { } |
44+
| codeql-go-tests/function.New | 0 | false | Node | NodeConstraint |
45+
| codeql-go-tests/function.New | 1 | false | Edge | EdgeConstraint |
46+
| codeql-go-tests/function.NodeConstraint | 0 | false | Edge | interface { } |
47+
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 0 | false | _ | interface { } |
48+
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 1 | false | _ | interface { string } |
49+
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 2 | false | _ | interface { } |
50+
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 0 | false | _ | interface { } |
51+
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 1 | false | _ | interface { string } |
52+
| codeql-go-tests/function.multipleAnonymousTypeParamsType | 2 | false | _ | interface { } |
53+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 0 | true | _ | interface { } |
54+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 1 | true | _ | interface { string } |
55+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 2 | true | _ | interface { } |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ where
1111
// Note that we cannot use the location of `tpt` itself as we currently fail
1212
// to extract an object for type parameters for methods on generic structs.
1313
exists(ty.getLocation())
14-
select ty.getQualifiedName(), tpt.getIndex(), tpt.getParamName(), tpt.getConstraint().pp()
14+
select ty.getQualifiedName(), tpt.getIndex(), tpt.isFromReceiver(), tpt.getParamName(), tpt.getConstraint().pp()

0 commit comments

Comments
 (0)