Skip to content

Commit 6074085

Browse files
committed
Interface unaliasing: don't confuse the empty interface with the type 'comparable'
1 parent 5388bb7 commit 6074085

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -932,10 +932,12 @@ pragma[nomagic]
932932
predicate unpackInterfaceType(
933933
InterfaceType intf, TOptInterfaceComponent c0, TOptInterfaceComponent c1,
934934
TOptInterfaceComponent c2, TOptInterfaceComponent c3, TOptInterfaceComponent c4,
935-
TOptInterfaceComponent e1, TOptInterfaceComponent e2, int nComponents, int nEmbeds
935+
TOptInterfaceComponent e1, TOptInterfaceComponent e2, int nComponents, int nEmbeds,
936+
boolean isComparable
936937
) {
937938
nComponents = count(int i | isInterfaceComponentWithQualifiedName(intf, i, _, _) and i >= 0) and
938939
nEmbeds = count(int i | isInterfaceComponentWithQualifiedName(intf, i, _, _) and i < 0) and
940+
(if intf.isOrEmbedsComparable() then isComparable = true else isComparable = false) and
939941
(
940942
if nComponents >= 1
941943
then c0 = any(InterfaceComponent ic | ic.isComponentOf(intf, 0))
@@ -977,14 +979,15 @@ pragma[nomagic]
977979
predicate unpackAndUnaliasInterfaceType(
978980
InterfaceType intf, TOptInterfaceComponent c0, TOptInterfaceComponent c1,
979981
TOptInterfaceComponent c2, TOptInterfaceComponent c3, TOptInterfaceComponent c4,
980-
TOptInterfaceComponent e1, TOptInterfaceComponent e2, int nComponents, int nEmbeds
982+
TOptInterfaceComponent e1, TOptInterfaceComponent e2, int nComponents, int nEmbeds,
983+
boolean isComparable
981984
) {
982985
exists(
983986
OptInterfaceComponent c0a, OptInterfaceComponent c1a, OptInterfaceComponent c2a,
984987
OptInterfaceComponent c3a, OptInterfaceComponent c4a, OptInterfaceComponent e1a,
985988
OptInterfaceComponent e2a
986989
|
987-
unpackInterfaceType(intf, c0a, c1a, c2a, c3a, c4a, e1a, e2a, nComponents, nEmbeds) and
990+
unpackInterfaceType(intf, c0a, c1a, c2a, c3a, c4a, e1a, e2a, nComponents, nEmbeds, isComparable) and
988991
c0 = c0a.getWithDeepUnaliasedType() and
989992
c1 = c1a.getWithDeepUnaliasedType() and
990993
c2 = c2a.getWithDeepUnaliasedType() and
@@ -1080,10 +1083,11 @@ class InterfaceType extends @interfacetype, CompositeType {
10801083
exists(
10811084
OptInterfaceComponent c0, OptInterfaceComponent c1, OptInterfaceComponent c2,
10821085
OptInterfaceComponent c3, OptInterfaceComponent c4, OptInterfaceComponent e1,
1083-
OptInterfaceComponent e2, int nComponents, int nEmbeds
1086+
OptInterfaceComponent e2, int nComponents, int nEmbeds, boolean isComparable
10841087
|
1085-
unpackAndUnaliasInterfaceType(this, c0, c1, c2, c3, c4, e1, e2, nComponents, nEmbeds) and
1086-
unpackInterfaceType(result, c0, c1, c2, c3, c4, e1, e2, nComponents, nEmbeds)
1088+
unpackAndUnaliasInterfaceType(this, c0, c1, c2, c3, c4, e1, e2, nComponents, nEmbeds,
1089+
isComparable) and
1090+
unpackInterfaceType(result, c0, c1, c2, c3, c4, e1, e2, nComponents, nEmbeds, isComparable)
10871091
)
10881092
}
10891093

0 commit comments

Comments
 (0)