Skip to content

Commit 38ee2d4

Browse files
committed
Fix bug by extracting more pointer types
1 parent 5094cb8 commit 38ee2d4

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

go/extractor/extractor.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,13 +1713,24 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
17131713
extractMethod(tw, meth)
17141714
}
17151715

1716+
underlyingInterface, underlyingIsInterface := underlying.(*types.Interface)
1717+
_, underlyingIsPointer := underlying.(*types.Pointer)
1718+
17161719
// associate all methods of underlying interface with this type
1717-
if underlyingInterface, ok := underlying.(*types.Interface); ok {
1720+
if underlyingIsInterface {
17181721
for i := 0; i < underlyingInterface.NumMethods(); i++ {
17191722
methlbl := extractMethod(tw, underlyingInterface.Method(i).Origin())
17201723
dbscheme.MethodHostsTable.Emit(tw, methlbl, lbl)
17211724
}
17221725
}
1726+
1727+
// If `underlying` is not a pointer or interface then methods can
1728+
// be defined on `origintp`. In this case we must ensure that
1729+
// `*origintp` is in the database, so that Method.hasQualifiedName
1730+
// correctly includes methods with receiver type `*origintp`.
1731+
if !underlyingIsInterface && !underlyingIsPointer {
1732+
extractType(tw, types.NewPointer(origintp))
1733+
}
17231734
case *types.TypeParam:
17241735
kind = dbscheme.TypeParamType.Index()
17251736
parentlbl := getTypeParamParentLabel(tw, tp)

go/ql/test/library-tests/semmle/go/Types/MethodCount.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
| * Foo | 1 |
22
| * P | 1 |
3+
| * S | 1 |
4+
| * SEmbedP | 1 |
5+
| * SEmbedS | 1 |
6+
| * T | 1 |
7+
| * T3 | 1 |
8+
| * T4 | 1 |
39
| * base | 2 |
410
| * embedder | 2 |
511
| * embedder2 | 2 |

go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName2.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.S | SMethod |
5959
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedS | SMethod |
6060
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.P | PMethod |
61+
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedP | PMethod |
6162
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.Foo | half |
6263
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T | half |
6364
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T3 | half |

go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName3.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | S | SMethod |
5959
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedS | SMethod |
6060
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | P | PMethod |
61+
| pkg1/promotedStructs.go:17:13:17:19 | PMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedP | PMethod |
6162
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | Foo | half |
6263
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T | half |
6364
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T3 | half |

go/ql/test/library-tests/semmle/go/Types/Methods.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
| * Foo | half | pkg1/tst.go:33:16:33:19 | half |
22
| * P | PMethod | pkg1/promotedStructs.go:17:13:17:19 | PMethod |
3+
| * S | SMethod | pkg1/promotedStructs.go:8:12:8:18 | SMethod |
4+
| * SEmbedP | PMethod | pkg1/promotedStructs.go:17:13:17:19 | PMethod |
5+
| * SEmbedS | SMethod | pkg1/promotedStructs.go:8:12:8:18 | SMethod |
6+
| * T | half | pkg1/tst.go:33:16:33:19 | half |
7+
| * T3 | half | pkg1/tst.go:33:16:33:19 | half |
8+
| * T4 | half | pkg1/tst.go:33:16:33:19 | half |
39
| * base | f | pkg1/embedding.go:10:13:10:13 | f |
410
| * base | g | pkg1/embedding.go:14:14:14:14 | g |
511
| * embedder | f | pkg1/embedding.go:10:13:10:13 | f |

0 commit comments

Comments
 (0)