Skip to content

Commit 15c90ad

Browse files
committed
remove redundant cast where the type is enforced by an equality comparison
1 parent e75448e commit 15c90ad

File tree

19 files changed

+26
-30
lines changed

19 files changed

+26
-30
lines changed

cpp/ql/lib/semmle/code/cpp/exprs/Expr.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Expr extends StmtParent, @expr {
3131
override Stmt getEnclosingStmt() {
3232
result = this.getParent().(Expr).getEnclosingStmt()
3333
or
34-
result = this.getParent().(Stmt)
34+
result = this.getParent()
3535
or
3636
exists(Expr other | result = other.getEnclosingStmt() and other.getConversion() = this)
3737
or

cpp/ql/src/Likely Bugs/Format/NonConstantFormat.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ predicate cannotContainString(Type t) {
6363

6464
predicate isNonConst(DataFlow::Node node) {
6565
exists(Expr e | e = node.asExpr() |
66-
exists(FunctionCall fc | fc = e.(FunctionCall) |
66+
exists(FunctionCall fc | fc = e |
6767
not (
6868
whitelistFunction(fc.getTarget(), _) or
6969
fc.getTarget().hasDefinition()
7070
)
7171
)
7272
or
73-
exists(Parameter p | p = e.(VariableAccess).getTarget().(Parameter) |
73+
exists(Parameter p | p = e.(VariableAccess).getTarget() |
7474
p.getFunction().getName() = "main" and p.getType() instanceof PointerType
7575
)
7676
or

cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import semmle.code.cpp.commons.DateTime
1010
* Get the top-level `BinaryOperation` enclosing the expression e.
1111
*/
1212
private BinaryOperation getATopLevelBinaryOperationExpression(Expr e) {
13-
result = e.getEnclosingElement().(BinaryOperation)
13+
result = e.getEnclosingElement()
1414
or
1515
result = getATopLevelBinaryOperationExpression(e.getEnclosingElement())
1616
}

cpp/ql/src/Metrics/Files/FCyclomaticComplexity.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import cpp
1515
from File f, float complexity, float loc
1616
where
1717
f.fromSource() and
18-
loc = sum(FunctionDeclarationEntry fde | fde.getFile() = f | fde.getNumberOfLines()).(float) and
18+
loc = sum(FunctionDeclarationEntry fde | fde.getFile() = f | fde.getNumberOfLines()) and
1919
if loc > 0
2020
then
2121
// Weighted average of complexity by function length

cpp/ql/src/jsf/4.22 Pointers and References/AV Rule 173.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import cpp
2626
from Assignment a, Variable global, Variable local
2727
where
2828
a.fromSource() and
29-
global.getAnAccess() = a.getLValue().(VariableAccess) and
29+
global.getAnAccess() = a.getLValue() and
3030
local.getAnAccess() = a.getRValue().(AddressOfExpr).getOperand() and
3131
local.hasSpecifier("auto") and
3232
(

cpp/ql/src/jsf/4.28 Portable Code/AV Rule 210.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class ExposingIntegralUnion extends Union {
4949
exists(MemberVariable mv1, MemberVariable mv2, IntegralType mv1tp, IntegralType mv2tp |
5050
mv1 = this.getAMemberVariable() and
5151
mv2 = this.getAMemberVariable() and
52-
mv1tp = mv1.getUnderlyingType().(IntegralType) and
52+
mv1tp = mv1.getUnderlyingType() and
5353
(
54-
mv2tp = mv2.getUnderlyingType().(IntegralType)
54+
mv2tp = mv2.getUnderlyingType()
5555
or
56-
mv2tp = mv2.getUnderlyingType().(ArrayType).getBaseType().getUnderlyingType().(IntegralType)
56+
mv2tp = mv2.getUnderlyingType().(ArrayType).getBaseType().getUnderlyingType()
5757
) and
5858
mv1tp.getSize() > mv2tp.getSize()
5959
)

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private module ControlFlowGraphImpl {
150150
* `TypeThrowable` which results in both `TypeError` and `TypeRuntimeException`.
151151
*/
152152
UncheckedThrowableType getAnUncheckedSubtype() {
153-
result = this.(UncheckedThrowableType)
153+
result = this
154154
or
155155
result instanceof TypeError and this instanceof TypeThrowable
156156
or

java/ql/lib/semmle/code/java/PrintAst.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ final class GenericTypeNode extends PrintAstNode, TGenericTypeNode {
665665
override Location getLocation() { none() }
666666

667667
override ElementNode getChild(int childIndex) {
668-
result.getElement().(TypeVariable) = ty.getTypeParameter(childIndex)
668+
result.getElement() = ty.getTypeParameter(childIndex)
669669
}
670670

671671
/**
@@ -686,7 +686,7 @@ final class GenericCallableNode extends PrintAstNode, TGenericCallableNode {
686686
override string toString() { result = "(Generic Parameters)" }
687687

688688
override ElementNode getChild(int childIndex) {
689-
result.getElement().(TypeVariable) = c.getTypeParameter(childIndex)
689+
result.getElement() = c.getTypeParameter(childIndex)
690690
}
691691

692692
/**

java/ql/lib/semmle/code/java/frameworks/JAXB.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class JaxbType extends Class {
5454
this.getAnAnnotation() = a and
5555
a.getType().(JaxbAnnotationType).hasName("XmlAccessorType")
5656
|
57-
result.getAnAccess() = a.getValue("value").(VarAccess)
57+
result.getAnAccess() = a.getValue("value")
5858
)
5959
}
6060

java/ql/lib/semmle/code/xml/MavenPom.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ class MavenRepo extends Folder {
395395
/**
396396
* Gets a Jar file contained within this repository.
397397
*/
398-
File getAJarFile() {
399-
result = this.getAChildContainer*().(File) and result.getExtension() = "jar"
400-
}
398+
File getAJarFile() { result = this.getAChildContainer*() and result.getExtension() = "jar" }
401399

402400
/**
403401
* Gets any jar artifacts in this repository that match the POM project definition. This is an

0 commit comments

Comments
 (0)