Skip to content

Commit f1fcb64

Browse files
authored
Merge pull request github#10992 from tamasvajk/kotlin-unused-extension
Kotlin: do not report on unused `object` extension parameters
2 parents bdb143c + 9cc7a30 commit f1fcb64

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ class RootdefCallable extends Callable {
281281
Parameter unusedParameter() {
282282
exists(int i | result = this.getParameter(i) |
283283
not exists(result.getAnAccess()) and
284-
not overrideAccess(this, i)
284+
not overrideAccess(this, i) and
285+
// Do not report unused parameters on extension parameters that are (companion) objects.
286+
not (
287+
result.isExtensionParameter() and
288+
(result.getType() instanceof CompanionObject or result.getType() instanceof ClassObject)
289+
)
285290
)
286291
}
287292

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ class B : A<B, Int> {
99
}
1010

1111
fun fn(a: Int = 10) {}
12+
13+
class C {
14+
companion object {}
15+
}
16+
17+
object O {}
18+
19+
fun C.fn() {}
20+
fun C.Companion.fn() {}
21+
fun O.fn() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
| Test.kt:11:8:11:18 | a | The parameter 'a' is never used. |
2+
| Test.kt:19:5:19:5 | <this> | The parameter '<this>' is never used. |

0 commit comments

Comments
 (0)