AA: fix expected type for lambda with explicit label
This commit is contained in:
committed by
Ilya Kirillov
parent
b29309478e
commit
14213ddad2
+6
-1
@@ -161,7 +161,12 @@ class KtFe10ExpressionTypeProvider(
|
||||
|
||||
override fun getExpectedType(expression: PsiElement): KtType? {
|
||||
val ktExpression = expression.getParentOfType<KtExpression>(false) ?: return null
|
||||
val parentExpression = ktExpression.parent
|
||||
val parentExpression = if (ktExpression.parent is KtLabeledExpression) {
|
||||
// lambda -> labeled expression -> lambda argument (value argument)
|
||||
ktExpression.parent.parent
|
||||
} else {
|
||||
ktExpression.parent
|
||||
}
|
||||
|
||||
// Unwrap specific expressions
|
||||
when (ktExpression) {
|
||||
|
||||
+12
@@ -238,6 +238,18 @@ public class Fe10IdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerate
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithExplicitTypeFromProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToExplicitLabel.kt")
|
||||
public void testSamWithReturnToExplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToExplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToImplicitLabel.kt")
|
||||
public void testSamWithReturnToImplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToImplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithTypeCast.kt")
|
||||
public void testSamWithTypeCast() throws Exception {
|
||||
|
||||
+7
-2
@@ -155,7 +155,11 @@ internal class KtFirExpressionTypeProvider(
|
||||
}
|
||||
|
||||
private fun PsiElement.getFunctionCallAsWithThisAsParameter(): KtCallWithArgument? {
|
||||
val valueArgument = unwrapQualified<KtValueArgument> { valueArg, expr -> valueArg.getArgumentExpression() == expr } ?: return null
|
||||
val valueArgument = unwrapQualified<KtValueArgument> { valueArg, expr ->
|
||||
// If `valueArg` is [KtLambdaArgument], its [getArgumentExpression] could be labeled expression (e.g., l@{ ... }).
|
||||
// That is not exactly `expr`, which would be [KtLambdaExpression]. So, we need [unwrap] here.
|
||||
valueArg.getArgumentExpression()?.unwrap() == expr
|
||||
} ?: return null
|
||||
val callExpression =
|
||||
(valueArgument.parent as? KtValueArgumentList)?.parent as? KtCallExpression
|
||||
?: valueArgument.parent as? KtCallExpression // KtLambdaArgument
|
||||
@@ -271,7 +275,8 @@ private inline fun <reified R : Any> PsiElement.unwrapQualified(check: (R, PsiEl
|
||||
|
||||
private val PsiElement.nonContainerParent: PsiElement?
|
||||
get() = when (val parent = parent) {
|
||||
is KtContainerNode -> parent.parent
|
||||
is KtContainerNode -> parent.nonContainerParent
|
||||
is KtLabeledExpression -> parent.nonContainerParent
|
||||
else -> parent
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -238,6 +238,18 @@ public class FirIdeDependentAnalysisSourceModuleExpectedExpressionTypeTestGenera
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithExplicitTypeFromProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToExplicitLabel.kt")
|
||||
public void testSamWithReturnToExplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToExplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToImplicitLabel.kt")
|
||||
public void testSamWithReturnToImplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToImplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithTypeCast.kt")
|
||||
public void testSamWithTypeCast() throws Exception {
|
||||
|
||||
+12
@@ -238,6 +238,18 @@ public class FirIdeNormalAnalysisSourceModuleExpectedExpressionTypeTestGenerated
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithExplicitTypeFromProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToExplicitLabel.kt")
|
||||
public void testSamWithReturnToExplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToExplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToImplicitLabel.kt")
|
||||
public void testSamWithReturnToImplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToImplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithTypeCast.kt")
|
||||
public void testSamWithTypeCast() throws Exception {
|
||||
|
||||
+12
@@ -238,6 +238,18 @@ public class FirStandaloneNormalAnalysisSourceModuleExpectedExpressionTypeTestGe
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithExplicitTypeFromProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToExplicitLabel.kt")
|
||||
public void testSamWithReturnToExplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToExplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithReturnToImplicitLabel.kt")
|
||||
public void testSamWithReturnToImplicitLabel() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/expressionTypeProvider/expectedExpressionType/samWithReturnToImplicitLabel.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("samWithTypeCast.kt")
|
||||
public void testSamWithTypeCast() throws Exception {
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
val baz = java.lang.Runnable l@{<caret> return@l }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: { return@l }
|
||||
expected type: java/lang/Runnable
|
||||
+1
@@ -0,0 +1 @@
|
||||
val baz = java.lang.Runnable {<caret> return@Runnable }
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
expression: { return@Runnable }
|
||||
expected type: java/lang/Runnable
|
||||
Reference in New Issue
Block a user