diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index bea57eeec8d7..c0eef233ba58 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -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) diff --git a/go/ql/test/library-tests/semmle/go/Types/MethodCount.expected b/go/ql/test/library-tests/semmle/go/Types/MethodCount.expected index e3f7ee63c641..9d576b0f4f66 100644 --- a/go/ql/test/library-tests/semmle/go/Types/MethodCount.expected +++ b/go/ql/test/library-tests/semmle/go/Types/MethodCount.expected @@ -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 | diff --git a/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName2.expected b/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName2.expected index 2ad41d3b8b4e..1f893728e300 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName2.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName2.expected @@ -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 | diff --git a/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName3.expected b/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName3.expected index bbf838ad3bb0..59a298e4b5f1 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName3.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Method_hasQualifiedName3.expected @@ -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 | diff --git a/go/ql/test/library-tests/semmle/go/Types/Methods.expected b/go/ql/test/library-tests/semmle/go/Types/Methods.expected index 895f2beb8ee6..2c17013c1862 100644 --- a/go/ql/test/library-tests/semmle/go/Types/Methods.expected +++ b/go/ql/test/library-tests/semmle/go/Types/Methods.expected @@ -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 |