Fix false positive "Insert explicit type arguments" intention

#KT-16139 Fixed
This commit is contained in:
Dmitry Gridin
2019-03-06 19:54:21 +03:00
parent 212e573c26
commit 6ba0a182bb
3 changed files with 15 additions and 1 deletions
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtTypeArgumentList
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.ErrorUtils
@@ -46,7 +47,7 @@ class InsertExplicitTypeArgumentsIntention :
val resolvedCall = element.getResolvedCall(bindingContext) ?: return false
val typeArgs = resolvedCall.typeArguments
return typeArgs.isNotEmpty() && typeArgs.values.none { ErrorUtils.containsErrorType(it) }
return typeArgs.isNotEmpty() && typeArgs.values.none { ErrorUtils.containsErrorType(it) || it is CapturedType }
}
fun applyTo(element: KtCallElement, shortenReferences: Boolean = true) {
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
class X<T>(val t: T)
fun <T> X<T>.getT(): T = t
fun <T> useX(x: X<out T>) {
x.getT<caret>()
}
@@ -9879,6 +9879,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/insertExplicitTypeArguments/insertTypeWithVarargs.kt");
}
@TestMetadata("notApplicableGenericType.kt")
public void testNotApplicableGenericType() throws Exception {
runTest("idea/testData/intentions/insertExplicitTypeArguments/notApplicableGenericType.kt");
}
@TestMetadata("simpleInsertTypeClass.kt")
public void testSimpleInsertTypeClass() throws Exception {
runTest("idea/testData/intentions/insertExplicitTypeArguments/simpleInsertTypeClass.kt");