Merge pull request #10992 from tamasvajk/kotlin-unused-extension

Kotlin: do not report on unused `object` extension parameters
This commit is contained in:
Tamás Vajk
2022-10-27 08:50:33 +02:00
committed by GitHub
3 changed files with 17 additions and 1 deletions

View File

@@ -281,7 +281,12 @@ class RootdefCallable extends Callable {
Parameter unusedParameter() {
exists(int i | result = this.getParameter(i) |
not exists(result.getAnAccess()) and
not overrideAccess(this, i)
not overrideAccess(this, i) and
// Do not report unused parameters on extension parameters that are (companion) objects.
not (
result.isExtensionParameter() and
(result.getType() instanceof CompanionObject or result.getType() instanceof ClassObject)
)
)
}

View File

@@ -9,3 +9,13 @@ class B : A<B, Int> {
}
fun fn(a: Int = 10) {}
class C {
companion object {}
}
object O {}
fun C.fn() {}
fun C.Companion.fn() {}
fun O.fn() {}

View File

@@ -1 +1,2 @@
| Test.kt:11:8:11:18 | a | The parameter 'a' is never used. |
| Test.kt:19:5:19:5 | <this> | The parameter '<this>' is never used. |