Skip to content

Commit

Permalink
Fix bug by extracting more pointer types
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-mc committed Nov 8, 2024
1 parent 5094cb8 commit 38ee2d4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion go/extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions go/ql/test/library-tests/semmle/go/Types/MethodCount.expected
Original file line number Diff line number Diff line change
@@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
6 changes: 6 additions & 0 deletions go/ql/test/library-tests/semmle/go/Types/Methods.expected
Original file line number Diff line number Diff line change
@@ -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 |
Expand Down

0 comments on commit 38ee2d4

Please sign in to comment.