mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Fix NamedType.getMethod to take interface embedding into account.
This commit is contained in:
@@ -575,6 +575,13 @@ class NamedType extends @namedtype, CompositeType {
|
||||
/** Gets the type which this type is defined to be. */
|
||||
Type getBaseType() { underlying_type(this, result) }
|
||||
|
||||
override Method getMethod(string m) {
|
||||
result = CompositeType.super.getMethod(m)
|
||||
or
|
||||
methodhosts(result, this) and
|
||||
result.getName() = m
|
||||
}
|
||||
|
||||
override Type getUnderlyingType() { result = getBaseType().getUnderlyingType() }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
| * Foo | 1 |
|
||||
| A | 1 |
|
||||
| A2 | 1 |
|
||||
| AC | 3 |
|
||||
| AEmbedded | 1 |
|
||||
| AExtended | 2 |
|
||||
| B | 2 |
|
||||
| C | 2 |
|
||||
| Foo | 1 |
|
||||
5
ql/test/library-tests/semmle/go/Types/MethodCount.ql
Normal file
5
ql/test/library-tests/semmle/go/Types/MethodCount.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import go
|
||||
|
||||
from Type t
|
||||
where t.getPackage().getName().regexpMatch("main|pkg1|pkg2")
|
||||
select t.pp(), strictcount(t.getMethod(_))
|
||||
15
ql/test/library-tests/semmle/go/Types/MethodTypes.expected
Normal file
15
ql/test/library-tests/semmle/go/Types/MethodTypes.expected
Normal file
@@ -0,0 +1,15 @@
|
||||
| A | m | func() |
|
||||
| A2 | m | func() |
|
||||
| AC | m | func() |
|
||||
| AC | n | func() |
|
||||
| AC | o | func() |
|
||||
| AEmbedded | m | func() |
|
||||
| AExtended | m | func() |
|
||||
| AExtended | n | func() |
|
||||
| B | m | func() |
|
||||
| B | n | func() |
|
||||
| C | n | func() |
|
||||
| C | o | func() |
|
||||
| T | half | func() Foo |
|
||||
| T3 | half | func() Foo |
|
||||
| T4 | half | func() Foo |
|
||||
7
ql/test/library-tests/semmle/go/Types/MethodTypes.ql
Normal file
7
ql/test/library-tests/semmle/go/Types/MethodTypes.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
import go
|
||||
|
||||
from NamedType t, string m, Type tp
|
||||
where
|
||||
exists(t.getEntity().getDeclaration()) and
|
||||
t.getBaseType().hasMethod(m, tp)
|
||||
select t, m, tp.pp()
|
||||
@@ -1,14 +1,14 @@
|
||||
| A | m | func() |
|
||||
| AC | m | func() |
|
||||
| AC | n | func() |
|
||||
| AC | o | func() |
|
||||
| AEmbedded | m | func() |
|
||||
| AExtended | m | func() |
|
||||
| AExtended | n | func() |
|
||||
| B | m | func() |
|
||||
| B | n | func() |
|
||||
| C | n | func() |
|
||||
| C | o | func() |
|
||||
| T | half | func() Foo |
|
||||
| T3 | half | func() Foo |
|
||||
| T4 | half | func() Foo |
|
||||
| * Foo | half | pkg1/tst.go:33:16:33:19 | half |
|
||||
| A | m | pkg1/interfaces.go:4:2:4:2 | m |
|
||||
| A2 | m | pkg1/interfaces.go:32:2:32:2 | m |
|
||||
| AC | m | pkg1/interfaces.go:4:2:4:2 | m |
|
||||
| AC | n | pkg1/interfaces.go:13:2:13:2 | n |
|
||||
| AC | o | pkg1/interfaces.go:14:2:14:2 | o |
|
||||
| AEmbedded | m | pkg1/interfaces.go:4:2:4:2 | m |
|
||||
| AExtended | m | pkg1/interfaces.go:4:2:4:2 | m |
|
||||
| AExtended | n | pkg1/interfaces.go:28:2:28:2 | n |
|
||||
| B | m | pkg1/interfaces.go:8:2:8:2 | m |
|
||||
| B | n | pkg1/interfaces.go:9:2:9:2 | n |
|
||||
| C | n | pkg1/interfaces.go:13:2:13:2 | n |
|
||||
| C | o | pkg1/interfaces.go:14:2:14:2 | o |
|
||||
| Foo | half | pkg1/tst.go:33:16:33:19 | half |
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import go
|
||||
|
||||
from NamedType t, string m, Type tp
|
||||
where
|
||||
exists(t.getEntity().getDeclaration()) and
|
||||
t.getBaseType().hasMethod(m, tp)
|
||||
select t, m, tp.pp()
|
||||
from Type t, string m
|
||||
where t.getPackage().getName().regexpMatch("main|pkg1|pkg2")
|
||||
select t.pp(), m, t.getMethod(m)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
| A | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.A |
|
||||
| A2 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.A2 |
|
||||
| AC | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.AC |
|
||||
| AEmbedded | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.AEmbedded |
|
||||
| AExtended | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.AExtended |
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
| A | A |
|
||||
| A2 | A2 |
|
||||
| AC | AC |
|
||||
| AEmbedded | AEmbedded |
|
||||
| AExtended | AExtended |
|
||||
|
||||
@@ -27,3 +27,7 @@ type AExtended interface {
|
||||
A
|
||||
n()
|
||||
}
|
||||
|
||||
type A2 interface {
|
||||
m()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user