Do not report "unused receiver" on companion objects
So #KT-19560 Fixed
This commit is contained in:
@@ -50,6 +50,10 @@ class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
||||
val receiverTypeReference = callableDeclaration.receiverTypeReference
|
||||
if (receiverTypeReference == null || receiverTypeReference.textRange.isEmpty) return
|
||||
|
||||
val context = receiverTypeReference.analyze()
|
||||
val receiverType = context[BindingContext.TYPE, receiverTypeReference] ?: return
|
||||
if (DescriptorUtils.isCompanionObject(receiverType.constructor.declarationDescriptor)) return
|
||||
|
||||
if (callableDeclaration.isOverridable() ||
|
||||
callableDeclaration.hasModifier(KtTokens.OVERRIDE_KEYWORD) ||
|
||||
callableDeclaration.hasModifier(KtTokens.OPERATOR_KEYWORD) ||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// PROBLEM: none
|
||||
|
||||
class Test {
|
||||
companion object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun <caret>Test.Companion.foo() = 42
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Test.foo()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
object Test
|
||||
|
||||
fun <caret>Test.foo() = 42
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x = Test
|
||||
x.foo()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
object Test
|
||||
|
||||
fun foo() = 42
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x = Test
|
||||
foo()
|
||||
}
|
||||
@@ -2327,12 +2327,24 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("companionPure.kt")
|
||||
public void testCompanionPure() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedReceiverParameter/companionPure.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("infix.kt")
|
||||
public void testInfix() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedReceiverParameter/infix.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("object.kt")
|
||||
public void testObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedReceiverParameter/object.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("operator.kt")
|
||||
public void testOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedReceiverParameter/operator.kt");
|
||||
|
||||
Reference in New Issue
Block a user