Skip to content

Commit 17afaf2

Browse files
committed
Go: Add test that shows that constraints might not be uniquely determined
1 parent 072b298 commit 17afaf2

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ numberOfTypeParameters
2222
| genericMethods.go:5:33:5:46 | GenericMethod1 | 1 |
2323
| genericMethods.go:7:6:7:28 | StructForGenericMethod2 | 1 |
2424
| genericMethods.go:9:37:9:50 | GenericMethod2 | 2 |
25+
| genericMethods.go:21:6:21:29 | StructWithDependentBound | 1 |
26+
| genericMethods.go:23:38:23:68 | GenericMethodWithDependentBound | 2 |
2527
#select
2628
| codeql-go-tests/function.EdgeConstraint | 0 | | Node | interface { } |
2729
| codeql-go-tests/function.Element | 0 | | S | interface { } |
@@ -51,6 +53,11 @@ numberOfTypeParameters
5153
| codeql-go-tests/function.StructForGenericMethod2 | 0 | | P2 | interface { } |
5254
| codeql-go-tests/function.StructForGenericMethod2.GenericMethod2 | 0 | | P4 | interface { } |
5355
| codeql-go-tests/function.StructForGenericMethod2.GenericMethod2 | 0 | from receiver | P3 | interface { } |
56+
| codeql-go-tests/function.StructWithDependentBound | 0 | | P5 | interface { } |
57+
| codeql-go-tests/function.StructWithDependentBound.GenericMethodWithDependentBound | 0 | | P7 | interface { ~[]P6 } |
58+
| codeql-go-tests/function.StructWithDependentBound.GenericMethodWithDependentBound | 0 | | P7 | interface { ~[]int } |
59+
| codeql-go-tests/function.StructWithDependentBound.GenericMethodWithDependentBound | 0 | | P7 | interface { ~[]string } |
60+
| codeql-go-tests/function.StructWithDependentBound.GenericMethodWithDependentBound | 0 | from receiver | P6 | interface { } |
5461
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 0 | | _ | interface { } |
5562
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 1 | | _ | interface { string } |
5663
| codeql-go-tests/function.multipleAnonymousTypeParamsFunc | 2 | | _ | interface { } |

‎go/ql/test/library-tests/semmle/go/Function/genericMethods.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ func generic_methods(s1 StructForGenericMethod1, s2 StructForGenericMethod2[int]
1717
s1.GenericMethod1("hello")
1818
s2.GenericMethod2(42)
1919
}
20+
21+
type StructWithDependentBound[P5 any] struct{}
22+
23+
func (*StructWithDependentBound[P6]) GenericMethodWithDependentBound[P7 ~[]P6](x P7) {}
24+
25+
func genericMethodDependentBounds(t1 StructWithDependentBound[int], t2 StructWithDependentBound[string]) {
26+
t1.GenericMethodWithDependentBound([]int{})
27+
t2.GenericMethodWithDependentBound([]string{})
28+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
| genericMethods.go:9:37:9:50 | GenericMethod2 | 0 | genericMethods.go:9:60:9:60 | x |
1616
| genericMethods.go:11:6:11:20 | generic_methods | 0 | genericMethods.go:11:22:11:23 | s1 |
1717
| genericMethods.go:11:6:11:20 | generic_methods | 1 | genericMethods.go:11:50:11:51 | s2 |
18+
| genericMethods.go:23:38:23:68 | GenericMethodWithDependentBound | 0 | genericMethods.go:23:80:23:80 | x |
19+
| genericMethods.go:25:6:25:33 | genericMethodDependentBounds | 0 | genericMethods.go:25:35:25:36 | t1 |
20+
| genericMethods.go:25:6:25:33 | genericMethodDependentBounds | 1 | genericMethods.go:25:69:25:70 | t2 |
1821
| main.go:7:6:7:7 | f1 | 0 | main.go:7:9:7:9 | x |
1922
| main.go:9:12:9:13 | f2 | 0 | main.go:9:15:9:15 | x |
2023
| 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
| genericMethods.go:5:1:5:63 | function declaration | MethodDecl | 0 | genericMethods.go:5:48:5:53 | type parameter declaration | 0 | genericMethods.go:5:48:5:49 | P1 | genericMethods.go:5:51:5:53 | any | interface { } |
2323
| genericMethods.go:7:6:7:45 | type declaration specifier | TypeSpec | 0 | genericMethods.go:7:30:7:35 | type parameter declaration | 0 | genericMethods.go:7:30:7:31 | P2 | genericMethods.go:7:33:7:35 | any | interface { } |
2424
| genericMethods.go:9:1:9:67 | function declaration | MethodDecl | 0 | genericMethods.go:9:52:9:57 | type parameter declaration | 0 | genericMethods.go:9:52:9:53 | P4 | genericMethods.go:9:55:9:57 | any | interface { } |
25+
| genericMethods.go:21:6:21:46 | type declaration specifier | TypeSpec | 0 | genericMethods.go:21:31:21:36 | type parameter declaration | 0 | genericMethods.go:21:31:21:32 | P5 | genericMethods.go:21:34:21:36 | any | interface { } |
26+
| genericMethods.go:23:1:23:87 | function declaration | MethodDecl | 0 | genericMethods.go:23:70:23:77 | type parameter declaration | 0 | genericMethods.go:23:70:23:71 | P7 | genericMethods.go:23:73:23:77 | type set literal | interface { ~[]P6 } |

0 commit comments

Comments
 (0)