PlatformExtensionReceiverOfInline: fix false positive with extension function with nullable type receiver
#KT-37256 Fixed
This commit is contained in:
committed by
Yan Zhulanow
parent
6868f53f46
commit
ded996bdf7
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
|||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
import org.jetbrains.kotlin.types.isNullabilityFlexible
|
import org.jetbrains.kotlin.types.isNullabilityFlexible
|
||||||
|
import org.jetbrains.kotlin.types.isNullable
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
import java.util.regex.PatternSyntaxException
|
import java.util.regex.PatternSyntaxException
|
||||||
import javax.swing.JPanel
|
import javax.swing.JPanel
|
||||||
@@ -68,7 +69,7 @@ class PlatformExtensionReceiverOfInlineInspection : AbstractKotlinInspection() {
|
|||||||
val extensionReceiverType = resolvedCall.extensionReceiver?.type ?: return
|
val extensionReceiverType = resolvedCall.extensionReceiver?.type ?: return
|
||||||
if (!extensionReceiverType.isNullabilityFlexible()) return
|
if (!extensionReceiverType.isNullabilityFlexible()) return
|
||||||
val descriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return
|
val descriptor = resolvedCall.resultingDescriptor as? FunctionDescriptor ?: return
|
||||||
if (!descriptor.isInline) return
|
if (!descriptor.isInline || descriptor.extensionReceiverParameter?.type?.isNullable() == true) return
|
||||||
|
|
||||||
val receiverExpression = expression.receiverExpression
|
val receiverExpression = expression.receiverExpression
|
||||||
val dataFlowValueFactory = receiverExpression.getResolutionFacade().getFrontendService(DataFlowValueFactory::class.java)
|
val dataFlowValueFactory = receiverExpression.getResolutionFacade().getFrontendService(DataFlowValueFactory::class.java)
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
public class JavaFoo {
|
||||||
|
public static String foo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
inline fun String?.contentToByte(): Byte {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
JavaFoo.foo().toBoolean()
|
||||||
|
JavaFoo.foo().contentToByte()
|
||||||
|
}
|
||||||
Vendored
+2
@@ -13,6 +13,8 @@ fun test() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun String.toBoolean(): Boolean = true
|
||||||
|
|
||||||
fun String.contentNotInline() {}
|
fun String.contentNotInline() {}
|
||||||
|
|
||||||
class My {
|
class My {
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.PlatformExtensionReceiverOfInlineInspection",
|
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.PlatformExtensionReceiverOfInlineInspection",
|
||||||
"withRuntime": "true",
|
"withRuntime": "true",
|
||||||
"isMultiModule": "false"
|
"isMultiModule": "true"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user