8000 Address review comments 2 · github/codeql-go@253ca2b · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 253ca2b

Browse files
owen-mcsmowton
authored andcommitted
Address review comments 2
1 parent 59aa742 commit 253ca2b

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

ql/lib/semmle/go/Types.qll

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Type extends @type {
8383
private predicate implementsNotComparable(InterfaceType i) {
8484
(
8585
forall(TypeSetLiteralType tslit | tslit = i.getAnEmbeddedTypeSetLiteral() |
86-
tslit.hasInTypeSet(this)
86+
tslit.includesType(this)
8787
) and
8888
(
8989
not i.hasMethod(_, _)
@@ -112,22 +112,21 @@ class Type extends @type {
112112
or
113113
u instanceof ArrayType and u.(ArrayType).getElementType().implementsComparable()
114114
or
115-
u instanceof InterfaceType and
116-
(
117-
not u instanceof BasicInterfaceType and
118-
if exists(u.(InterfaceType).getAnEmbeddedTypeSetLiteral())
115+
exists(InterfaceType uif | uif = u |
116+
not uif instanceof BasicInterfaceType and
117+
if exists(uif.getAnEmbeddedTypeSetLiteral())
119118
then
119+
// All types in the intersection of all the embedded type set
120+
// literals must implement comparable.
120121
forall(Type intersectionType |
121-
intersectionType = u.(InterfaceType).getAnEmbeddedTypeSetLiteral().getATerm().getType() and
122-
forall(TypeSetLiteralType tslit |
123-
tslit = u.(InterfaceType).getAnEmbeddedTypeSetLiteral()
124-
|
122+
intersectionType = uif.getAnEmbeddedTypeSetLiteral().getATerm().getType() and
123+
forall(TypeSetLiteralType tslit | tslit = uif.getAnEmbeddedTypeSetLiteral() |
125124
intersectionType = tslit.getATerm().getType()
126125
)
127126
|
128127
intersectionType.implementsComparable()
129128
)
130-
else u.(InterfaceType).isOrEmbedsComparable()
129+
else uif.isOrEmbedsComparable()
131130
)
132131
)
133132
}
@@ -610,8 +609,8 @@ class PointerType extends @pointertype, CompositeType {
610609
override string toString() { result = "pointer type" }
611610
}
612611

613-
private newtype TTerm =
614-
MkTerm(TypeSetLiteralType tslit, int index) { component_types(tslit, index, _, _) }
612+
private newtype TTypeSetTerm =
613+
MkTypeSetTerm(TypeSetLiteralType tslit, int index) { component_types(tslit, index, _, _) }
615614

616615
/**
617616
* A term in a type set literal.
@@ -622,13 +621,13 @@ private newtype TTerm =
622621
* ~string
623622
* ```
624623
*/
625-
class Term extends TTerm {
624+
class TypeSetTerm extends TTypeSetTerm {
626625
boolean tilde;
627626
Type tp;
628627

629-
Term() {
628+
TypeSetTerm() {
630629
exists(TypeSetLiteralType tslit, int index |
631-
this = MkTerm(tslit, index) and
630+
this = MkTypeSetTerm(tslit, index) and
632631
(
633632
component_types(tslit, index, "", tp) and
634633
tilde = false
@@ -651,7 +650,7 @@ class Term extends TTerm {
651650
Type getType() { result = tp }
652651

653652
/** Holds if `t` is in the type set of this term. */
654-
predicate hasInTypeSet(Type t) { if tilde = false then t = tp else t.getUnderlyingType(< 6D40 /span>) = tp }
653+
predicate includesType(Type t) { if tilde = false then t = tp else t.getUnderlyingType() = tp }
655654

656655
/** Gets a pretty-printed representation of this term. */
657656
string pp() {
@@ -661,15 +660,15 @@ class Term extends TTerm {
661660
}
662661

663662
/** Gets a textual representation of this element. */
664-
string toString() { result = "term" }
663+
string toString() { result = "type set term" }
665664
}
666665

667-
private Term getIntersection(Term term1, Term term2) {
666+
private TypeSetTerm getIntersection(TypeSetTerm term1, TypeSetTerm term2) {
668667
term1.getType() = term2.getType() and
669668
if term1.hasTilde() then result = term2 else result = term1
670669
}
671670

672-
Term getTermInIntersection(TypeSetLiteralType a, TypeSetLiteralType b) {
671+
TypeSetTerm getTermInIntersection(TypeSetLiteralType a, TypeSetLiteralType b) {
673672
result = getIntersection(a.getATerm(), b.getATerm())
674673
}
675674

@@ -689,13 +688,13 @@ Term getTermInIntersection(TypeSetLiteralType a, TypeSetLiteralType b) {
689688
*/
690689
class TypeSetLiteralType extends @typesetliteraltype, CompositeType {
691690
/** Gets the `i`th term in this type set literal. */
692-
Term getTerm(int i) { result = MkTerm(this, i) }
691+
TypeSetTerm getTerm(int i) { result = MkTypeSetTerm(this, i) }
693692

694693
/** Gets a term in this type set literal. */
695-
Term getATerm() { result = getTerm(_) }
694+
TypeSetTerm getATerm() { result = getTerm(_) }
696695

697696
/** Holds if `t` is in the type set of this type set literal. */
698-
predicate hasInTypeSet(Type t) { exists(int i | this.getTerm(i).hasInTypeSet(t)) }
697+
predicate includesType(Type t) { this.getATerm().includesType(t) }
699698

700699
/**
701700
* Gets the interface type specified by just this type set literal, if it
@@ -705,15 +704,15 @@ class TypeSetLiteralType extends @typesetliteraltype, CompositeType {
705704
* the bound in a type parameter declaration.
706705
*/
707706
InterfaceType getInterfaceType() {
708-
this = result.getExplicitlyEmbeddedTypeSetLiteral(0) and
709-
not exists(result.getExplicitlyEmbeddedTypeSetLiteral(1)) and
707+
this = result.getDirectlyEmbeddedTypeSetLiteral(0) and
708+
not exists(result.getDirectlyEmbeddedTypeSetLiteral(1)) and
710709
not result.hasMethod(_, _) and
711-
not exists(result.getAnExplicitlyEmbeddedInterface())
710+
not exists(result.getADirectlyEmbeddedInterface())
712711
}
713712

714713
language[monotonicAggregates]
715714
override string pp() {
716-
result = concat(Term t, int i | t = this.getTerm(i) | t.pp(), " | " order by i)
715+
result = concat(TypeSetTerm t, int i | t = this.getTerm(i) | t.pp(), " | " order by i)
717716
}
718717

719718
override string toString() { result = "type set literal type" }
@@ -723,30 +722,32 @@ class TypeSetLiteralType extends @typesetliteraltype, CompositeType {
723722
class InterfaceType extends @interfacetype, CompositeType {
724723
/** Gets the type of method `name` of this interface type. */
725724
Type getMethodType(string name) {
725+
// Note that negative indices correspond to embedded interfaces and type
726+
// set literals.
726727
exists(int i | i >= 0 | component_types(this, i, name, result))
727728
}
728729

729730
override predicate hasMethod(string m, SignatureType t) { t = this.getMethodType(m) }
730731

731732
/**
732-
* Holds if `tp` is an explicitly embedded type with index `index`.
733+
* Holds if `tp` is a directly embedded type with index `index`.
733734
*
734-
* `tp` is either a type set literal type or its underlyign type is an
735+
* `tp` (or its underlying type) is either a type set literal type or an
735736
* interface type.
736737
*/
737-
private predicate hasExplicitlyEmbeddedType(int index, Type tp) {
738+
private predicate hasDirectlyEmbeddedType(int index, Type tp) {
738739
index >= 0 and component_types(this, -(index + 1), _, tp)
739740
}
740741

741742
/**
742-
* Gets a type whose underlying type is an interface that is explicitly
743+
* Gets a type whose underlying type is an interface that is directly
743744
* embedded into this interface.
744745
*
745746
* Note that the methods of the embedded interface are already considered
746747
* as part of the method set of this interface.
747748
*/
748-
Type getAnExplicitlyEmbeddedInterface() {
749-
hasExplicitlyEmbeddedType(_, result) and result.getUnderlyingType() instanceof InterfaceType
749+
Type getADirectlyEmbeddedInterface() {
750+
hasDirectlyEmbeddedType(_, result) and result.getUnderlyingType() instanceof InterfaceType
750751
}
751752

752753
/**
@@ -757,9 +758,9 @@ class InterfaceType extends @interfacetype, CompositeType {
757758
* as part of the method set of this interface.
758759
*/
759760
Type getAnEmbeddedInterface() {
760-
result = this.getAnExplicitlyEmbeddedInterface() or
761+
result = this.getADirectlyEmbeddedInterface() or
761762
result =
762-
this.getAnExplicitlyEmbeddedInterface()
763+
this.getADirectlyEmbeddedInterface()
763764
.getUnderlyingType()
764765
.(InterfaceType)
765766
.getAnEmbeddedInterface()
@@ -778,10 +779,10 @@ class InterfaceType extends @interfacetype, CompositeType {
778779
* Gets the type set literal with index `index` from the definition of this
779780
* interface type.
780781
*
781-
* Note that the indexing includes embedded interfaces but not methods.
782+
* Note that the indexes are not contiguous.
782783
*/
783-
TypeSetLiteralType getExplicitlyEmbeddedTypeSetLiteral(int index) {
784-
hasExplicitlyEmbeddedType(index, result)
784+
TypeSetLiteralType getDirectlyEmbeddedTypeSetLiteral(int index) {
785+
hasDirectlyEmbeddedType(index, result)
785786
}
786787

787788
/**
@@ -790,9 +791,9 @@ class InterfaceType extends @interfacetype, CompositeType {
790791
* This includes type set literals of embedded interfaces.
791792
*/
792793
TypeSetLiteralType getAnEmbeddedTypeSetLiteral() {
793-
result = this.getExplicitlyEmbeddedTypeSetLiteral(_) or
794+
result = this.getDirectlyEmbeddedTypeSetLiteral(_) or
794795
result =
795-
getAnExplicitlyEmbeddedInterface()
796+
getADirectlyEmbeddedInterface()
796797
.getUnderlyingType()
797798
.(InterfaceType)
798799
.getAnEmbeddedTypeSetLiteral()

0 commit comments

Comments
 (0)
0