Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions ql/ql/src/codeql_ql/style/RedundantCastQuery.qll
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import ql

class RedundantInlineCast extends AstNode instanceof InlineCast {
Type t;

RedundantInlineCast() {
t = unique( | | super.getType()) and
(
exists(Type t |
t = unique( | | super.getType()) and
// noopt can require explicit casts
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
|
// The cast is to the type the base expression already has
t = unique( | | super.getBase().getType())
or
Expand All @@ -23,9 +24,7 @@ class RedundantInlineCast extends AstNode instanceof InlineCast {
target = unique( | | call.getTarget()) and
t = unique( | | target.getParameterType(i))
)
) and
// noopt can require explicit casts
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
)
}

TypeExpr getTypeExpr() { result = super.getTypeExpr() }
Expand All @@ -49,15 +48,16 @@ private class AnyCast extends AstNode instanceof FullAggregate {
// `foo = any(Bar b)` is effectively a cast to `Bar`.
class RedundantAnyCast extends AstNode instanceof ComparisonFormula {
AnyCast cast;
Expr operand;

RedundantAnyCast() {
super.getOperator() = "=" and
super.getAnOperand() = cast and
super.getAnOperand() = operand and
cast != operand and
unique( | | operand.getType()).getASuperType*() =
unique( | | cast.getTypeExpr().getResolvedType()) and
exists(Expr operand |
super.getAnOperand() = operand and
cast != operand and
unique( | | operand.getType()).getASuperType*() =
unique( | | cast.getTypeExpr().getResolvedType())
) and
not this.getEnclosingPredicate().getAnAnnotation() instanceof NoOpt
}

Expand Down
2 changes: 2 additions & 0 deletions ql/ql/test/queries/performance/VarUnusedInDisjunct/Test.qll
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,6 @@ class HasField extends Big {
or
this.toString().matches("%foo") // <- field only defined here.
}

Big getField() { result = field }
}
4 changes: 2 additions & 2 deletions ql/ql/test/queries/style/Misspelling/Misspelling.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
| Test.qll:4:7:4:26 | Class PublicallyAccessible | This class name contains the common misspelling 'publically', which should instead be 'publicly'. |
| Test.qll:5:3:5:20 | FieldDecl | This field name contains the common misspelling 'occurences', which should instead be 'occurrences'. |
| Test.qll:10:13:10:23 | ClassPredicate hasAgrument | This predicate name contains the common misspelling 'agrument', which should instead be 'argument'. |
| Test.qll:13:1:16:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
| Test.qll:17:7:17:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |
| Test.qll:15:1:18:3 | QLDoc | This comment contains the non-US spelling 'colour', which should instead be 'color'. |
| Test.qll:19:7:19:17 | Class AnalysedInt | This class name contains the non-US spelling 'analysed', which should instead be 'analyzed'. |
2 changes: 2 additions & 0 deletions ql/ql/test/queries/style/Misspelling/Test.qll
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class PublicallyAccessible extends string {

// should be argument
predicate hasAgrument() { none() }

int getNum() { result = numOccurences }
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field name 'numOccurences' contains a misspelling - it should be 'numOccurrences' with double 'r'.

Note: See the diff below for a potential fix:

@@ -2,14 +2,14 @@
  * A string that's deliberately mispelled (and so is that last word).
  */
 class PublicallyAccessible extends string {
-  int numOccurences; // should be 'occurrences'
+  int numOccurrences; // should be 'occurrences'
 
-  PublicallyAccessible() { this = "publically" and numOccurences = 123 }
+  PublicallyAccessible() { this = "publically" and numOccurrences = 123 }
 
   // should be argument
   predicate hasAgrument() { none() }
 
-  int getNum() { result = numOccurences }
+  int getNum() { result = numOccurrences }
 }
 
 /**

Copilot uses AI. Check for mistakes.

}

/**
Expand Down
2 changes: 2 additions & 0 deletions ql/ql/test/queries/style/UseInstanceofExtension/Foo.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Inst3 extends string {
Range range;

Inst3() { this = range }

Range getRange() { result = range }
}

class Inst4 extends string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| Foo.qll:7:7:7:10 | Class Inst | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
| Foo.qll:15:7:15:11 | Class Inst2 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
| Foo.qll:21:7:21:11 | Class Inst3 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
| Foo.qll:27:7:27:11 | Class Inst4 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
| Foo.qll:29:7:29:11 | Class Inst4 | Consider defining this class as non-extending subtype of $@. | Foo.qll:1:7:1:11 | Class Range | Range |
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
| test.qll:62:7:65:14 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
| test.qll:68:7:71:13 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
| test.qll:74:7:77:13 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
| test.qll:87:3:90:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
| test.qll:128:3:134:3 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
| test.qll:89:3:92:9 | Disjunction | This formula of 4 predicate calls can be replaced with a single call on a set literal, improving readability. |
| test.qll:130:3:136:3 | Disjunction | This formula of 4 comparisons can be replaced with a single equality on a set literal, improving readability. |
2 changes: 2 additions & 0 deletions ql/ql/test/queries/style/UseSetLiteral/test.qll
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class MyTest8Class extends int {
predicate is(int x) { x = this }

int get() { result = this }

string getS() { result = s }
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method references field 's' but this field is not defined in the MyTest8Class. This will cause a compilation error.

Copilot uses AI. Check for mistakes.

}

predicate test9(MyTest8Class c) {
Expand Down
Loading