Skip to content

Commit e0f0987

Browse files
committed
Go: Make isFromReceiver and actual predicate
1 parent 9c1f5c9 commit e0f0987

3 files changed

Lines changed: 38 additions & 38 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ class TypeParamType extends @typeparamtype, CompositeType {
396396
int getIndex() { typeparam(this, _, _, _, result, _) }
397397

398398
/** Holds if this type parameter type is declared as part of a receiver */
399-
boolean isFromReceiver() { typeparam(this, _, _, _, _, result) }
399+
predicate isFromReceiver() { typeparam(this, _, _, _, _, true) }
400400

401401
override string pp() { result = this.getParamName() }
402402

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 | 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 { } |
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 | from receiver | TF1 | interface { } |
31+
| codeql-go-tests/function.GenericStruct1.g1 | 0 | from receiver | 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 | from receiver | SF2 | interface { } |
35+
| codeql-go-tests/function.GenericStruct2.f2 | 1 | from receiver | TF2 | interface { } |
36+
| codeql-go-tests/function.GenericStruct2.g2 | 0 | from receiver | SG2 | interface { } |
37+
| codeql-go-tests/function.GenericStruct2.g2 | 1 | from receiver | 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 | from receiver | Node | NodeConstraint |
41+
| codeql-go-tests/function.Graph.ShortestPath | 1 | from receiver | Edge | EdgeConstraint |
42+
| codeql-go-tests/function.List | 0 | | T | interface { } |
43+
| codeql-go-tests/function.List.MyLen | 0 | from receiver | 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 | from receiver | _ | interface { } |
54+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 1 | from receiver | _ | interface { string } |
55+
| codeql-go-tests/function.multipleAnonymousTypeParamsType.f | 2 | from receiver | _ | interface { } |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ query predicate numberOfTypeParameters(TypeParamParentEntity parent, int n) {
55
n = strictcount(TypeParamType tpt | tpt.getParent() = parent)
66
}
77

8-
from TypeParamType tpt, TypeParamParentEntity ty
8+
from TypeParamType tpt, TypeParamParentEntity ty, string fr
99
where
1010
ty = tpt.getParent() and
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.
13-
exists(ty.getLocation())
14-
select ty.getQualifiedName(), tpt.getIndex(), tpt.isFromReceiver(), tpt.getParamName(),
15-
tpt.getConstraint().pp()
13+
exists(ty.getLocation()) and
14+
if tpt.isFromReceiver() then fr = "from receiver" else fr = ""
15+
select ty.getQualifiedName(), tpt.getIndex(), fr, tpt.getParamName(), tpt.getConstraint().pp()

0 commit comments

Comments
 (0)