"Surround with lambda" quickfix: suggest for suspend function

#KT-34371 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-29 11:02:36 +09:00
committed by Ilya Kirillov
parent 44c34ab8c3
commit 1bc72f0b32
4 changed files with 19 additions and 2 deletions
@@ -4,7 +4,7 @@ import com.intellij.codeInsight.intention.HighPriorityAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.builtins.isFunctionOrSuspendFunctionType
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
@@ -68,7 +68,7 @@ class SurroundWithLambdaFix(
}
}
if (!expectedType.isFunctionType) return null
if (!expectedType.isFunctionOrSuspendFunctionType) return null
if (expectedType.arguments.size != 1) return null
val lambdaReturnType = expectedType.arguments[0].type
@@ -0,0 +1,6 @@
// "Surround with lambda" "true"
fun foo(action: suspend () -> String) {}
fun usage() {
foo("oraora"<caret>)
}
@@ -0,0 +1,6 @@
// "Surround with lambda" "true"
fun foo(action: suspend () -> String) {}
fun usage() {
foo({ "oraora" })
}
@@ -13584,6 +13584,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/typeMismatch/paramTypeLambdaMatchSubclass.kt");
}
@TestMetadata("paramTypeLambdaMatchSuspend.kt")
public void testParamTypeLambdaMatchSuspend() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/paramTypeLambdaMatchSuspend.kt");
}
@TestMetadata("paramTypeLambdaMismatch.kt")
public void testParamTypeLambdaMismatch() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/paramTypeLambdaMismatch.kt");