Skip to content

Commit 6c781b5

Browse files
authored
Merge pull request github#10789 from tamasvajk/kotlin-useless-params
Kotlin: reduce FPs in useless parameter check for Kotlin code
2 parents 10aab81 + 0d6da9c commit 6c781b5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

java/ql/lib/semmle/code/java/deadcode/DeadCode.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ class RootdefCallable extends Callable {
304304
this.getAnAnnotation() instanceof OverrideAnnotation
305305
or
306306
this.hasModifier("override")
307+
or
308+
// Exclude generated callables, such as `...$default` ones extracted from Kotlin code.
309+
this.isCompilerGenerated()
310+
or
311+
// Exclude Kotlin serialization constructors.
312+
this.(Constructor)
313+
.getParameterType(this.getNumberOfParameters() - 1)
314+
.(RefType)
315+
.hasQualifiedName("kotlinx.serialization.internal", "SerializationConstructorMarker")
307316
}
308317
}
309318

java/ql/test/kotlin/query-tests/UselessParameter/Test.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ class B : A<B, Int> {
77
println("a")
88
}
99
}
10+
11+
fun fn(a: Int = 10) {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Test.kt:11:8:11:18 | a | The parameter 'a' is never used. |

0 commit comments

Comments
 (0)