Fix bug by extracting more pointer types

This commit is contained in:
Owen Mansel-Chan
2024-11-08 11:54:08 +00:00
parent 5094cb851b
commit 38ee2d418a
5 changed files with 26 additions and 1 deletions

View File

@@ -1713,13 +1713,24 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
extractMethod(tw, meth)
}
underlyingInterface, underlyingIsInterface := underlying.(*types.Interface)
_, underlyingIsPointer := underlying.(*types.Pointer)
// associate all methods of underlying interface with this type
if underlyingInterface, ok := underlying.(*types.Interface); ok {
if underlyingIsInterface {
for i := 0; i < underlyingInterface.NumMethods(); i++ {
methlbl := extractMethod(tw, underlyingInterface.Method(i).Origin())
dbscheme.MethodHostsTable.Emit(tw, methlbl, lbl)
}
}
// If `underlying` is not a pointer or interface then methods can
// be defined on `origintp`. In this case we must ensure that
// `*origintp` is in the database, so that Method.hasQualifiedName
// correctly includes methods with receiver type `*origintp`.
if !underlyingIsInterface && !underlyingIsPointer {
extractType(tw, types.NewPointer(origintp))
}
case *types.TypeParam:
kind = dbscheme.TypeParamType.Index()
parentlbl := getTypeParamParentLabel(tw, tp)

View File

@@ -1,5 +1,11 @@
| * Foo | 1 |
| * P | 1 |
| * S | 1 |
| * SEmbedP | 1 |
| * SEmbedS | 1 |
| * T | 1 |
| * T3 | 1 |
| * T4 | 1 |
| * base | 2 |
| * embedder | 2 |
| * embedder2 | 2 |

View File

@@ -58,6 +58,7 @@
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.S | SMethod |
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedS | SMethod |
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.P | PMethod |
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedP | PMethod |
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.Foo | half |
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T | half |
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T3 | half |

View File

@@ -58,6 +58,7 @@
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | S | SMethod |
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedS | SMethod |
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | P | PMethod |
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedP | PMethod |
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | Foo | half |
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T | half |
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T3 | half |

View File

@@ -1,5 +1,11 @@
| * Foo | half | pkg1/tst.go:33:16:33:19 | half |
| * P | PMethod | pkg1/promotedStructs.go:17:13:17:19 | PMethod |
| * S | SMethod | pkg1/promotedStructs.go:8:12:8:18 | SMethod |
| * SEmbedP | PMethod | pkg1/promotedStructs.go:17:13:17:19 | PMethod |
| * SEmbedS | SMethod | pkg1/promotedStructs.go:8:12:8:18 | SMethod |
| * T | half | pkg1/tst.go:33:16:33:19 | half |
| * T3 | half | pkg1/tst.go:33:16:33:19 | half |
| * T4 | half | pkg1/tst.go:33:16:33:19 | half |
| * base | f | pkg1/embedding.go:10:13:10:13 | f |
| * base | g | pkg1/embedding.go:14:14:14:14 | g |
| * embedder | f | pkg1/embedding.go:10:13:10:13 | f |