mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Note that all interface types are considered comparable as of Go 1.20
This commit is contained in:
@@ -112,22 +112,10 @@ class Type extends @type {
|
||||
or
|
||||
u instanceof ArrayType and u.(ArrayType).getElementType().implementsComparable()
|
||||
or
|
||||
exists(InterfaceType uif | uif = u |
|
||||
not uif instanceof BasicInterfaceType and
|
||||
if exists(uif.getAnEmbeddedTypeSetLiteral())
|
||||
then
|
||||
// All types in the intersection of all the embedded type set
|
||||
// literals must implement comparable.
|
||||
forall(Type intersectionType |
|
||||
intersectionType = uif.getAnEmbeddedTypeSetLiteral().getATerm().getType() and
|
||||
forall(TypeSetLiteralType tslit | tslit = uif.getAnEmbeddedTypeSetLiteral() |
|
||||
intersectionType = tslit.getATerm().getType()
|
||||
)
|
||||
|
|
||||
intersectionType.implementsComparable()
|
||||
)
|
||||
else uif.isOrEmbedsComparable()
|
||||
)
|
||||
// As of Go 1.20, any interface type satisfies the `comparable` constraint, even though comparison
|
||||
// may panic at runtime depending on the actual object's concrete type.
|
||||
// Look at git history here if you need the old definition.
|
||||
u instanceof InterfaceType
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,31 +51,31 @@
|
||||
| interface.go:95:6:95:8 | i18 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.i18 |
|
||||
| interface.go:101:6:101:8 | i19 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.i19 |
|
||||
| interface.go:105:6:105:8 | i20 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.i20 |
|
||||
| interface.go:110:6:110:19 | testComparable | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable |
|
||||
| interface.go:111:6:111:20 | testComparable0 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable0 |
|
||||
| interface.go:112:6:112:20 | testComparable1 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable1 |
|
||||
| interface.go:113:6:113:20 | testComparable2 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable2 |
|
||||
| interface.go:114:6:114:20 | testComparable3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable3 |
|
||||
| interface.go:115:6:115:20 | testComparable4 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable4 |
|
||||
| interface.go:116:6:116:20 | testComparable5 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable5 |
|
||||
| interface.go:117:6:117:20 | testComparable6 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable6 |
|
||||
| interface.go:118:6:118:20 | testComparable7 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable7 |
|
||||
| interface.go:119:6:119:20 | testComparable8 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable8 |
|
||||
| interface.go:120:6:120:20 | testComparable9 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable9 |
|
||||
| interface.go:121:6:121:21 | testComparable10 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable10 |
|
||||
| interface.go:122:6:122:21 | testComparable11 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable11 |
|
||||
| interface.go:123:6:123:21 | testComparable12 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable12 |
|
||||
| interface.go:124:6:124:21 | testComparable13 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable13 |
|
||||
| interface.go:125:6:125:21 | testComparable14 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable14 |
|
||||
| interface.go:126:6:126:21 | testComparable15 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable15 |
|
||||
| interface.go:127:6:127:21 | testComparable16 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable16 |
|
||||
| interface.go:128:6:128:21 | testComparable17 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable17 |
|
||||
| interface.go:129:6:129:21 | testComparable18 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable18 |
|
||||
| interface.go:130:6:130:21 | testComparable19 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable19 |
|
||||
| interface.go:131:6:131:21 | testComparable20 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable20 |
|
||||
| interface.go:132:6:132:21 | testComparable21 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable21 |
|
||||
| interface.go:133:6:133:21 | testComparable22 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable22 |
|
||||
| interface.go:134:6:134:21 | testComparable23 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable23 |
|
||||
| interface.go:114:6:114:19 | testComparable | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable |
|
||||
| interface.go:115:6:115:20 | testComparable0 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable0 |
|
||||
| interface.go:116:6:116:20 | testComparable1 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable1 |
|
||||
| interface.go:117:6:117:20 | testComparable2 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable2 |
|
||||
| interface.go:118:6:118:20 | testComparable3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable3 |
|
||||
| interface.go:119:6:119:20 | testComparable4 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable4 |
|
||||
| interface.go:120:6:120:20 | testComparable5 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable5 |
|
||||
| interface.go:121:6:121:20 | testComparable6 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable6 |
|
||||
| interface.go:122:6:122:20 | testComparable7 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable7 |
|
||||
| interface.go:123:6:123:20 | testComparable8 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable8 |
|
||||
| interface.go:124:6:124:20 | testComparable9 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable9 |
|
||||
| interface.go:125:6:125:21 | testComparable10 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable10 |
|
||||
| interface.go:126:6:126:21 | testComparable11 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable11 |
|
||||
| interface.go:127:6:127:21 | testComparable12 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable12 |
|
||||
| interface.go:128:6:128:21 | testComparable13 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable13 |
|
||||
| interface.go:129:6:129:21 | testComparable14 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable14 |
|
||||
| interface.go:130:6:130:21 | testComparable15 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable15 |
|
||||
| interface.go:131:6:131:21 | testComparable16 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable16 |
|
||||
| interface.go:132:6:132:21 | testComparable17 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable17 |
|
||||
| interface.go:133:6:133:21 | testComparable18 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable18 |
|
||||
| interface.go:134:6:134:21 | testComparable19 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable19 |
|
||||
| interface.go:135:6:135:21 | testComparable20 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable20 |
|
||||
| interface.go:136:6:136:21 | testComparable21 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable21 |
|
||||
| interface.go:137:6:137:21 | testComparable22 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable22 |
|
||||
| interface.go:138:6:138:21 | testComparable23 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable23 |
|
||||
| pkg1/embedding.go:8:6:8:9 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.base |
|
||||
| pkg1/embedding.go:19:6:19:13 | embedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder |
|
||||
| pkg1/embedding.go:22:6:22:16 | ptrembedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.ptrembedder |
|
||||
|
||||
@@ -51,31 +51,31 @@
|
||||
| interface.go:95:6:95:8 | i18 | i18 |
|
||||
| interface.go:101:6:101:8 | i19 | i19 |
|
||||
| interface.go:105:6:105:8 | i20 | i20 |
|
||||
| interface.go:110:6:110:19 | testComparable | testComparable |
|
||||
| interface.go:111:6:111:20 | testComparable0 | testComparable0 |
|
||||
| interface.go:112:6:112:20 | testComparable1 | testComparable1 |
|
||||
| interface.go:113:6:113:20 | testComparable2 | testComparable2 |
|
||||
| interface.go:114:6:114:20 | testComparable3 | testComparable3 |
|
||||
| interface.go:115:6:115:20 | testComparable4 | testComparable4 |
|
||||
| interface.go:116:6:116:20 | testComparable5 | testComparable5 |
|
||||
| interface.go:117:6:117:20 | testComparable6 | testComparable6 |
|
||||
| interface.go:118:6:118:20 | testComparable7 | testComparable7 |
|
||||
| interface.go:119:6:119:20 | testComparable8 | testComparable8 |
|
||||
| interface.go:120:6:120:20 | testComparable9 | testComparable9 |
|
||||
| interface.go:121:6:121:21 | testComparable10 | testComparable10 |
|
||||
| interface.go:122:6:122:21 | testComparable11 | testComparable11 |
|
||||
| interface.go:123:6:123:21 | testComparable12 | testComparable12 |
|
||||
| interface.go:124:6:124:21 | testComparable13 | testComparable13 |
|
||||
| interface.go:125:6:125:21 | testComparable14 | testComparable14 |
|
||||
| interface.go:126:6:126:21 | testComparable15 | testComparable15 |
|
||||
| interface.go:127:6:127:21 | testComparable16 | testComparable16 |
|
||||
| interface.go:128:6:128:21 | testComparable17 | testComparable17 |
|
||||
| interface.go:129:6:129:21 | testComparable18 | testComparable18 |
|
||||
| interface.go:130:6:130:21 | testComparable19 | testComparable19 |
|
||||
| interface.go:131:6:131:21 | testComparable20 | testComparable20 |
|
||||
| interface.go:132:6:132:21 | testComparable21 | testComparable21 |
|
||||
| interface.go:133:6:133:21 | testComparable22 | testComparable22 |
|
||||
| interface.go:134:6:134:21 | testComparable23 | testComparable23 |
|
||||
| interface.go:114:6:114:19 | testComparable | testComparable |
|
||||
| interface.go:115:6:115:20 | testComparable0 | testComparable0 |
|
||||
| interface.go:116:6:116:20 | testComparable1 | testComparable1 |
|
||||
| interface.go:117:6:117:20 | testComparable2 | testComparable2 |
|
||||
| interface.go:118:6:118:20 | testComparable3 | testComparable3 |
|
||||
| interface.go:119:6:119:20 | testComparable4 | testComparable4 |
|
||||
| interface.go:120:6:120:20 | testComparable5 | testComparable5 |
|
||||
| interface.go:121:6:121:20 | testComparable6 | testComparable6 |
|
||||
| interface.go:122:6:122:20 | testComparable7 | testComparable7 |
|
||||
| interface.go:123:6:123:20 | testComparable8 | testComparable8 |
|
||||
| interface.go:124:6:124:20 | testComparable9 | testComparable9 |
|
||||
| interface.go:125:6:125:21 | testComparable10 | testComparable10 |
|
||||
| interface.go:126:6:126:21 | testComparable11 | testComparable11 |
|
||||
| interface.go:127:6:127:21 | testComparable12 | testComparable12 |
|
||||
| interface.go:128:6:128:21 | testComparable13 | testComparable13 |
|
||||
| interface.go:129:6:129:21 | testComparable14 | testComparable14 |
|
||||
| interface.go:130:6:130:21 | testComparable15 | testComparable15 |
|
||||
| interface.go:131:6:131:21 | testComparable16 | testComparable16 |
|
||||
| interface.go:132:6:132:21 | testComparable17 | testComparable17 |
|
||||
| interface.go:133:6:133:21 | testComparable18 | testComparable18 |
|
||||
| interface.go:134:6:134:21 | testComparable19 | testComparable19 |
|
||||
| interface.go:135:6:135:21 | testComparable20 | testComparable20 |
|
||||
| interface.go:136:6:136:21 | testComparable21 | testComparable21 |
|
||||
| interface.go:137:6:137:21 | testComparable22 | testComparable22 |
|
||||
| interface.go:138:6:138:21 | testComparable23 | testComparable23 |
|
||||
| pkg1/embedding.go:8:6:8:9 | base | base |
|
||||
| pkg1/embedding.go:19:6:19:13 | embedder | embedder |
|
||||
| pkg1/embedding.go:22:6:22:16 | ptrembedder | ptrembedder |
|
||||
|
||||
@@ -107,28 +107,32 @@ type i20 interface {
|
||||
StringB() string
|
||||
}
|
||||
|
||||
type testComparable[T comparable] struct{} // $ implementsComparable
|
||||
type testComparable0[T0 i0] struct{} // $ implementsComparable
|
||||
type testComparable1[T1 i1] struct{} // $ implementsComparable
|
||||
type testComparable2[T2 i2] struct{} // $ implementsComparable
|
||||
type testComparable3[T3 i3] struct{} // $ implementsComparable
|
||||
type testComparable4[T4 i4] struct{} // $ implementsComparable
|
||||
type testComparable5[T5 i5] struct{} // does not implement comparable
|
||||
type testComparable6[T6 i6] struct{} // does not implement comparable
|
||||
type testComparable7[T7 i7] struct{} // $ implementsComparable
|
||||
type testComparable8[T8 i8] struct{} // does not implement comparable
|
||||
type testComparable9[T9 i9] struct{} // does not implement comparable
|
||||
type testComparable10[T10 i10] struct{} // $ implementsComparable
|
||||
type testComparable11[T11 i11] struct{} // $ implementsComparable
|
||||
type testComparable12[T12 i12] struct{} // does not implement comparable
|
||||
type testComparable13[T13 i13] struct{} // does not implement comparable
|
||||
type testComparable14[T14 i14] struct{} // $ implementsComparable
|
||||
type testComparable15[T15 i15] struct{} // $ implementsComparable
|
||||
type testComparable16[T16 i16] struct{} // does not implement comparable
|
||||
type testComparable17[T17 i17] struct{} // does not implement comparable
|
||||
type testComparable18[T18 i18] struct{} // $ implementsComparable
|
||||
type testComparable19[T19 i19] struct{} // does not implement comparable
|
||||
type testComparable20[T20 i20] struct{} // $ implementsComparable
|
||||
type testComparable21[T21 ~[]byte | string] struct{} // does not implement comparable
|
||||
type testComparable22[T22 any] struct{} // does not implement comparable
|
||||
type testComparable23[T23 ~[5]byte | string] struct{} // $ implementsComparable
|
||||
// These used to distinguish strictly-comparable interfaces (i.e. those which will not panic at runtime on attempting a comparison),
|
||||
// which were required to satisfy the `comparable` type constraint in Go <1.20. Now they all match `comparable` as all interfaces
|
||||
// are accepted. I mark those which are also strictly comparable for the future in case we want to expose that concept in QL.
|
||||
|
||||
type testComparable[T comparable] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable0[T0 i0] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable1[T1 i1] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable2[T2 i2] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable3[T3 i3] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable4[T4 i4] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable5[T5 i5] struct{} // $ implementsComparable
|
||||
type testComparable6[T6 i6] struct{} // $ implementsComparable
|
||||
type testComparable7[T7 i7] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable8[T8 i8] struct{} // $ implementsComparable
|
||||
type testComparable9[T9 i9] struct{} // $ implementsComparable
|
||||
type testComparable10[T10 i10] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable11[T11 i11] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable12[T12 i12] struct{} // $ implementsComparable
|
||||
type testComparable13[T13 i13] struct{} // $ implementsComparable
|
||||
type testComparable14[T14 i14] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable15[T15 i15] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable16[T16 i16] struct{} // $ implementsComparable
|
||||
type testComparable17[T17 i17] struct{} // $ implementsComparable
|
||||
type testComparable18[T18 i18] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable19[T19 i19] struct{} // $ implementsComparable
|
||||
type testComparable20[T20 i20] struct{} // $ implementsComparable isStrictlyComparable
|
||||
type testComparable21[T21 ~[]byte | string] struct{} // $ implementsComparable
|
||||
type testComparable22[T22 any] struct{} // $ implementsComparable
|
||||
type testComparable23[T23 ~[5]byte | string] struct{} // $ implementsComparable isStrictlyComparable
|
||||
|
||||
Reference in New Issue
Block a user