PlatformExtensionReceiverOfInline: fix false positive with extension function with nullable type receiver

#KT-37256 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-03-24 17:01:51 +09:00
committed by Yan Zhulanow
parent 6868f53f46
commit ded996bdf7
6 changed files with 29 additions and 2 deletions
@@ -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.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.isNullabilityFlexible
import org.jetbrains.kotlin.types.isNullable
import java.awt.BorderLayout
import java.util.regex.PatternSyntaxException
import javax.swing.JPanel
@@ -68,7 +69,7 @@ class PlatformExtensionReceiverOfInlineInspection : AbstractKotlinInspection() {
val extensionReceiverType = resolvedCall.extensionReceiver?.type ?: return
if (!extensionReceiverType.isNullabilityFlexible()) 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 dataFlowValueFactory = receiverExpression.getResolutionFacade().getFrontendService(DataFlowValueFactory::class.java)
@@ -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>
@@ -0,0 +1,5 @@
public class JavaFoo {
public static String foo() {
return null;
}
}
@@ -0,0 +1,8 @@
inline fun String?.contentToByte(): Byte {
return 0
}
fun main() {
JavaFoo.foo().toBoolean()
JavaFoo.foo().contentToByte()
}
@@ -13,6 +13,8 @@ fun test() {
}
}
inline fun String.toBoolean(): Boolean = true
fun String.contentNotInline() {}
class My {
@@ -1,5 +1,5 @@
{
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.PlatformExtensionReceiverOfInlineInspection",
"withRuntime": "true",
"isMultiModule": "false"
"isMultiModule": "true"
}