From 796db771040c1f8526f1336b593541b2570baddb Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Fri, 27 Sep 2024 15:03:09 +0100 Subject: [PATCH 1/2] Add comments noting methods from embedded interfaces are already included --- go/extractor/extractor.go | 3 +++ go/ql/lib/semmle/go/Types.qll | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index 81e7e99dee54..f372cc161805 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -1618,6 +1618,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label { case *types.Interface: kind = dbscheme.InterfaceType.Index() for i := 0; i < tp.NumMethods(); i++ { + // Note that methods coming from embedded interfaces can be + // accessed through `Method(i)`, so there is no need to + // deal with them separately. meth := tp.Method(i) // Note that methods do not have a parent scope, so they are diff --git a/go/ql/lib/semmle/go/Types.qll b/go/ql/lib/semmle/go/Types.qll index 6f0defead24b..c93a962cc50d 100644 --- a/go/ql/lib/semmle/go/Types.qll +++ b/go/ql/lib/semmle/go/Types.qll @@ -737,12 +737,17 @@ class TypeSetLiteralType extends @typesetliteraltype, CompositeType { override string toString() { result = "type set literal type" } } +predicate foo(NamedType t, string name, Type mt) { + t.getUnderlyingType().(InterfaceType).getMethodType(name) = mt +} + /** An interface type. */ class InterfaceType extends @interfacetype, CompositeType { /** Gets the type of method `name` of this interface type. */ Type getMethodType(string name) { // Note that negative indices correspond to embedded interfaces and type - // set literals. + // set literals. Note also that methods coming from embedded interfaces + // have already been included in `component_types`. exists(int i | i >= 0 | component_types(this, i, name, result)) } From ca68aaa0de0c782c4d82f6f4a3f95d005090715c Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Fri, 27 Sep 2024 19:07:00 +0100 Subject: [PATCH 2/2] Remove test code --- go/ql/lib/semmle/go/Types.qll | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go/ql/lib/semmle/go/Types.qll b/go/ql/lib/semmle/go/Types.qll index c93a962cc50d..f7bb6afe3d7a 100644 --- a/go/ql/lib/semmle/go/Types.qll +++ b/go/ql/lib/semmle/go/Types.qll @@ -737,10 +737,6 @@ class TypeSetLiteralType extends @typesetliteraltype, CompositeType { override string toString() { result = "type set literal type" } } -predicate foo(NamedType t, string name, Type mt) { - t.getUnderlyingType().(InterfaceType).getMethodType(name) = mt -} - /** An interface type. */ class InterfaceType extends @interfacetype, CompositeType { /** Gets the type of method `name` of this interface type. */