Skip to content

Commit a277bcb

Browse files
authored
Merge pull request #17941 from owen-mc/go/fix/missing-method-qualified-names
Go: fix missing qualified names for some promoted methods
2 parents fed240a + 0b24235 commit a277bcb

20 files changed

+153
-13
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)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed a bug which meant that some qualified names for promoted methods were not being recognised in some very specific circumstances.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
| pkg1/embedding.go:28:24:28:31 | embedder | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
3333
| pkg1/embedding.go:36:2:36:5 | base | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
3434
| pkg1/embedding.go:37:2:37:2 | f | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
35+
| pkg1/promotedStructs.go:5:2:5:7 | SField | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
36+
| pkg1/promotedStructs.go:14:2:14:7 | PField | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
37+
| pkg1/promotedStructs.go:22:22:22:22 | S | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
38+
| pkg1/promotedStructs.go:25:22:25:22 | P | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
3539
| pkg1/tst.go:4:2:4:2 | f | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
3640
| pkg1/tst.go:5:2:5:4 | Foo | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |
3741
| pkg1/tst.go:6:2:6:4 | Bar | package github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
| pkg1/embedding.go:28:24:28:31 | embedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder3 | embedder |
4444
| pkg1/embedding.go:36:2:36:5 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder4 | base |
4545
| pkg1/embedding.go:37:2:37:2 | f | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder4 | f |
46+
| pkg1/promotedStructs.go:5:2:5:7 | SField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.S | SField |
47+
| pkg1/promotedStructs.go:5:2:5:7 | SField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedS | SField |
48+
| pkg1/promotedStructs.go:14:2:14:7 | PField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.P | PField |
49+
| pkg1/promotedStructs.go:14:2:14:7 | PField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedP | PField |
50+
| pkg1/promotedStructs.go:22:22:22:22 | S | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedS | S |
51+
| pkg1/promotedStructs.go:25:22:25:22 | P | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedP | P |
4652
| pkg1/tst.go:4:2:4:2 | f | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T | f |
4753
| pkg1/tst.go:5:2:5:4 | Foo | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T | Foo |
4854
| pkg1/tst.go:6:2:6:4 | Bar | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T | Bar |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
| pkg1/embedding.go:28:24:28:31 | embedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | embedder3 | embedder |
4444
| pkg1/embedding.go:36:2:36:5 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | embedder4 | base |
4545
| pkg1/embedding.go:37:2:37:2 | f | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | embedder4 | f |
46+
| pkg1/promotedStructs.go:5:2:5:7 | SField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | S | SField |
47+
| pkg1/promotedStructs.go:5:2:5:7 | SField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedS | SField |
48+
| pkg1/promotedStructs.go:14:2:14:7 | PField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | P | PField |
49+
| pkg1/promotedStructs.go:14:2:14:7 | PField | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedP | PField |
50+
| pkg1/promotedStructs.go:22:22:22:22 | S | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedS | S |
51+
| pkg1/promotedStructs.go:25:22:25:22 | P | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedP | P |
4652
| pkg1/tst.go:4:2:4:2 | f | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T | f |
4753
| pkg1/tst.go:5:2:5:4 | Foo | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T | Foo |
4854
| pkg1/tst.go:6:2:6:4 | Bar | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T | Bar |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
| * Foo | 1 |
2+
| * P | 1 |
3+
| * S | 1 |
4+
| * SEmbedP | 1 |
5+
| * SEmbedS | 1 |
6+
| * T | 1 |
7+
| * T3 | 1 |
8+
| * T4 | 1 |
29
| * base | 2 |
310
| * embedder | 2 |
411
| * embedder2 | 2 |
@@ -16,6 +23,8 @@
1623
| GenericInterface | 1 |
1724
| MixedExportedAndNot | 2 |
1825
| MyInterface | 17 |
26+
| S | 1 |
27+
| SEmbedS | 1 |
1928
| T | 1 |
2029
| T3 | 1 |
2130
| T4 | 1 |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
| pkg1/interfaces.go:31:6:31:7 | A2 | m | func() |
5151
| pkg1/interfaces.go:35:6:35:24 | MixedExportedAndNot | Exported | func() |
5252
| pkg1/interfaces.go:35:6:35:24 | MixedExportedAndNot | notExported | func() |
53+
| pkg1/promotedStructs.go:22:6:22:12 | SEmbedS | SMethod | func() interface { } |
5354
| pkg1/tst.go:3:6:3:6 | T | half | func() Foo |
5455
| pkg1/tst.go:14:6:14:7 | T3 | half | func() Foo |
5556
| pkg1/tst.go:19:6:19:7 | T4 | half | func() Foo |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
| pkg1/interfaces.go:32:2:32:2 | m | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.A2 | m |
5656
| pkg1/interfaces.go:36:2:36:9 | Exported | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.MixedExportedAndNot | Exported |
5757
| pkg1/interfaces.go:37:2:37:12 | notExported | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.MixedExportedAndNot | notExported |
58+
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.S | SMethod |
59+
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.SEmbedS | SMethod |
60+
| 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 |
5862
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.Foo | half |
5963
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.T | half |
6064
| 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
| pkg1/interfaces.go:32:2:32:2 | m | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | A2 | m |
5656
| pkg1/interfaces.go:36:2:36:9 | Exported | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | MixedExportedAndNot | Exported |
5757
| pkg1/interfaces.go:37:2:37:12 | notExported | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | MixedExportedAndNot | notExported |
58+
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | S | SMethod |
59+
| pkg1/promotedStructs.go:8:12:8:18 | SMethod | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | SEmbedS | SMethod |
60+
| 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 |
5862
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | Foo | half |
5963
| pkg1/tst.go:33:16:33:19 | half | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1 | T | half |
6064
| 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
| * Foo | half | pkg1/tst.go:33:16:33:19 | half |
2+
| * 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 |
29
| * base | f | pkg1/embedding.go:10:13:10:13 | f |
310
| * base | g | pkg1/embedding.go:14:14:14:14 | g |
411
| * embedder | f | pkg1/embedding.go:10:13:10:13 | f |
@@ -45,6 +52,8 @@
4552
| MyInterface | dummy18 | generic.go:62:2:62:8 | dummy18 |
4653
| MyInterface | dummy19 | generic.go:63:2:63:8 | dummy19 |
4754
| MyInterface | dummy20 | generic.go:64:2:64:8 | dummy20 |
55+
| S | SMethod | pkg1/promotedStructs.go:8:12:8:18 | SMethod |
56+
| SEmbedS | SMethod | pkg1/promotedStructs.go:8:12:8:18 | SMethod |
4857
| T | half | pkg1/tst.go:33:16:33:19 | half |
4958
| T3 | half | pkg1/tst.go:33:16:33:19 | half |
5059
| T4 | half | pkg1/tst.go:33:16:33:19 | half |

0 commit comments

Comments
 (0)