Skip to content

Commit 84d7828

Browse files
committed
Interface types: distinguish otherwise-identical interfaces with non-exported methods defined in different packages
1 parent 14ef824 commit 84d7828

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,9 @@ private predicate isInterfaceComponentWithQualifiedName(
927927

928928
private newtype TOptInterfaceComponent =
929929
MkNoIComponent() or
930-
MkSomeIComponent(string name, Type tp) { component_types(any(InterfaceType i), _, name, tp) }
930+
MkSomeIComponent(string name, Type tp) {
931+
isInterfaceComponentWithQualifiedName(any(InterfaceType i), _, name, tp)
932+
}
931933

932934
private class OptInterfaceComponent extends TOptInterfaceComponent {
933935
OptInterfaceComponent getWithDeepUnaliasedType() {
@@ -947,7 +949,7 @@ private class InterfaceComponent extends MkSomeIComponent {
947949

948950
predicate isComponentOf(InterfaceType intf, int i) {
949951
exists(string name, Type tp |
950-
component_types(intf, i, name, tp) and
952+
isInterfaceComponentWithQualifiedName(intf, i, name, tp) and
951953
this = MkSomeIComponent(name, tp)
952954
)
953955
}
@@ -1135,8 +1137,8 @@ class InterfaceType extends @interfacetype, CompositeType {
11351137
i = 5 or
11361138
this.hasDeepUnaliasedComponentTypesUpTo(unaliased, i - 1)
11371139
) and
1138-
exists(string name, Type tp | component_types(this, i, name, tp) |
1139-
component_types(unaliased, i, name, tp.getDeepUnaliasedType())
1140+
exists(string name, Type tp | isInterfaceComponentWithQualifiedName(this, i, name, tp) |
1141+
isInterfaceComponentWithQualifiedName(unaliased, i, name, tp.getDeepUnaliasedType())
11401142
)
11411143
}
11421144

@@ -1147,21 +1149,23 @@ class InterfaceType extends @interfacetype, CompositeType {
11471149
i = 3 or
11481150
this.hasDeepUnaliasedEmbeddedTypesUpTo(unaliased, i - 1)
11491151
) and
1150-
exists(string name, Type tp | component_types(this, -i, name, tp) |
1151-
component_types(unaliased, -i, name, tp.getDeepUnaliasedType())
1152+
exists(string name, Type tp | isInterfaceComponentWithQualifiedName(this, -i, name, tp) |
1153+
isInterfaceComponentWithQualifiedName(unaliased, -i, name, tp.getDeepUnaliasedType())
11521154
)
11531155
}
11541156

11551157
override InterfaceType getDeepUnaliasedType() {
11561158
result = this.getDeepUnaliasedTypeCandidate() and
11571159
exists(int nComponents |
1158-
nComponents = count(int i | component_types(this, i, _, _) and i >= 0)
1160+
nComponents = count(int i | isInterfaceComponentWithQualifiedName(this, i, _, _) and i >= 0)
11591161
|
11601162
this.hasDeepUnaliasedComponentTypesUpTo(result, nComponents - 1)
11611163
or
11621164
nComponents <= 5
11631165
) and
1164-
exists(int nEmbeds | nEmbeds = count(int i | component_types(this, i, _, _) and i < 0) |
1166+
exists(int nEmbeds |
1167+
nEmbeds = count(int i | isInterfaceComponentWithQualifiedName(this, i, _, _) and i < 0)
1168+
|
11651169
// Note no -1 here, because the first embedded type is at -1
11661170
this.hasDeepUnaliasedEmbeddedTypesUpTo(result, nEmbeds)
11671171
or

0 commit comments

Comments
 (0)