diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt index 55068e11849..83d3eb53136 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinExpressionTypeProvider.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.RenderingFormat @@ -38,13 +39,14 @@ class KotlinExpressionTypeProvider : ExpressionTypeProvider() { elementAt.parentsWithSelf.filterIsInstance().filter { it.shouldShowType() }.toList() private fun KtExpression.shouldShowType() = when(this) { + is KtFunctionLiteral -> false is KtFunction -> !hasBlockBody() && !hasDeclaredReturnType() is KtProperty -> typeReference == null is KtPropertyAccessor -> false is KtDestructuringDeclarationEntry -> true is KtStatementExpression, is KtDestructuringDeclaration -> false is KtIfExpression, is KtLoopExpression, is KtWhenExpression, is KtTryExpression -> parent !is KtBlockExpression - else -> true + else -> getQualifiedExpressionForSelector() == null } override fun getInformationHint(element: KtExpression): String { diff --git a/idea/testData/codeInsight/expressionType/Lambda.kt b/idea/testData/codeInsight/expressionType/Lambda.kt new file mode 100644 index 00000000000..b85e0361e12 --- /dev/null +++ b/idea/testData/codeInsight/expressionType/Lambda.kt @@ -0,0 +1,7 @@ +val x = listOf(1).map { q -> println(q) } + +// TYPE: q -> Int +// TYPE: println(q) -> Unit +// TYPE: { q -> println(q) } -> (Int) → Unit +// TYPE: listOf(1).map { q -> println(q) } -> List<Unit> +// TYPE: val x = listOf(1).map { q -> println(q) } -> List<Unit> diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java index 28db5cb7c57..a12ba9286d8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/ExpressionTypeTestGenerated.java @@ -53,6 +53,12 @@ public class ExpressionTypeTestGenerated extends AbstractExpressionTypeTest { doTest(fileName); } + @TestMetadata("Lambda.kt") + public void testLambda() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/Lambda.kt"); + doTest(fileName); + } + @TestMetadata("MultiDeclaration.kt") public void testMultiDeclaration() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/codeInsight/expressionType/MultiDeclaration.kt");